Rev. | c3a256ccb4a9a5823695d2237d31680b12931560 |
---|---|
Größe | 1,279 Bytes |
Zeit | 2022-11-29 23:54:33 |
Autor | yoshy |
Log Message | [MOD] キャプション書式化機能でキャプションの取得と書式化を行う機能の区別を明確にした
|
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;
}
}
}