System.Security.Cryptography
その記事によると、256ビットの復号化キーと512ビットの検証キーが生成され、それらはRijndaelアルゴリズムを使用するため、すでに名前空間にあるC#実装が必要です。
作業を行う2つの関数は次のとおりです。
private static string EncryptString(string clearText,
string strKey, string strIv) {
byte[] plainText = Encoding.UTF8.GetBytes(clearText);
byte[] key = Encoding.UTF8.GetBytes(strKey);
// a simple initialization vector
byte[] iv = Encoding.UTF8.GetBytes(strIv);
RijndaelManaged rijndael = new RijndaelManaged();
//Define the Mode
rijndael.Mode = CipherMode.CBC;
ICryptoTransform aesEncryptor = rijndael.CreateEncryptor(key, iv);
MemoryStream ms = new MemoryStream();
// writing data to MemoryStream
CryptoStream cs = new CryptoStream(ms, aesEncryptor, CryptoStreamMode.Write);
cs.Write(plainText, 0, plainText.Length);
cs.FlushFinalBlock();
byte[] CipherBytes = ms.ToArray();
ms.Close();
cs.Close();
return Convert.ToBase64String(CipherBytes);
}
と :
public static string DecryptString(string cipherText,
string strKey, string strIv) {
byte[] cipheredData = Convert.FromBase64String(cipherText);
byte[] key = Encoding.UTF8.GetBytes(strKey);
byte[] iv = Encoding.UTF8.GetBytes(strIv);
RijndaelManaged rijndael = new RijndaelManaged();
rijndael.Mode = CipherMode.CBC;
ICryptoTransform decryptor = rijndael.CreateDecryptor(key, iv);
MemoryStream ms = new MemoryStream(cipheredData);
CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read);
byte[] plainTextData = new byte[cipheredData.Length];
int decryptedByteCount = cs.Read(plainTextData, 0, plainTextData.Length);
ms.Close();
cs.Close();
return Encoding.UTF8.GetString(plainTextData, 0, decryptedByteCount);
}
そして、2番目の質問については、生成されたマシンキーは人間が読める形式の16進文字列ですが、理解することはできません。
これがお役に立てば幸いです。