• R/O
  • HTTP
  • SSH
  • HTTPS

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

File Info

Rev. c3a256ccb4a9a5823695d2237d31680b12931560
Größe 1,279 Bytes
Zeit 2022-11-29 23:54:33
Autor yoshy
Log Message

[MOD] キャプション書式化機能でキャプションの取得と書式化を行う機能の区別を明確にした

Content

using System.Security.Cryptography;
using System.Text;

namespace CleanAuLait.Core.Converter
{
    public static class CryptoHelper
    {
        public static byte[] GenerateEntropy(int length)
        {
            return RandomNumberGenerator.GetBytes(length);
        }

        public static byte[] ProtectData(string str, byte[] entropy)
        {
            if (str == null)
            {
                return null;
            }

            if (entropy == null || entropy.Length == 0)
            {
                return null;
            }

            byte[] data = Encoding.UTF8.GetBytes(str);
            byte[] encrypted = ProtectedData.Protect(data, entropy, DataProtectionScope.CurrentUser);

            return encrypted;
        }

        public static string UnprotectData(byte[] encrypted, byte[] entropy)
        {
            if (encrypted == null || encrypted.Length == 0)
            {
                return null;
            }

            if (entropy == null || entropy.Length == 0)
            {
                return null;
            }

            byte[] data = ProtectedData.Unprotect(encrypted, entropy, DataProtectionScope.CurrentUser);
            string str = Encoding.UTF8.GetString(data);

            return str;
        }
    }
}