その記事によると、256ビットの復号鍵と512ビットの検証鍵が生成され、彼らはRijndaelアルゴリズムで行くので、あなたはすでにあり、それのC#実装を必要としますSystem.Security.Cryptography
名前空間。
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番目の質問については、生成されたのmachineKeyは人間読み込み可能ですが、あなたが理解できない16進数の文字列である。ここ
は、仕事をする二つの機能でありますそれを出す。
このヘルプが欲しいです。
これらはマシンキーと一致しますか? string strKey、string strIv – user441365
strKeyはマシンキーです。初期化ベクトル文字列を表すstrIvは、必要な値を渡すことができる単純な文字列です。 – amrfaissal
次にstrIvをハードコードできますか?また、strKEyはvalidationKeyまたはdecryptionKeyと一致する必要がありますか? – user441365