1

Rijndael 暗号化アルゴリズムは、次の例の 3 つのストリームを使用して .NET に実装されています: Rinjdael

これらのストリームが何をしているのか誰か説明してもらえますか? それらはどのように/なぜ使用されますか?

// Declare the streams used
// to encrypt to an in memory
// array of bytes.
MemoryStream msEncrypt = null;
CryptoStream csEncrypt = null;
StreamWriter swEncrypt = null;

// Declare the RijndaelManaged object
// used to encrypt the data.
RijndaelManaged aesAlg = null;

try
{
    // Create a RijndaelManaged object
    // with the specified key and IV.
    aesAlg = new RijndaelManaged();
    aesAlg.Key = Key;
    aesAlg.IV = IV;


    // Create a encryptor to perform the stream transform.
    ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);

    // Create the streams used for encryption.
    msEncrypt = new MemoryStream();
    csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write);
    swEncrypt = new StreamWriter(csEncrypt);

    //Write all data to the stream.
    swEncrypt.Write(plainText);

}
4

1 に答える 1

3

swEncryptStreamWriter- その仕事はテキストをバイナリデータに変換することです

csEncryptCryptoStream- その仕事は、バイナリデータを暗号化されたバイナリデータに変換することです

msEncryptMemoryStream- その仕事は、与えられたデータをメモリに保存することなので、後で取り出すことができます

それらをすべてまとめると、基本的に、一方の端でプレーンテキストを書き込み、もう一方の端から暗号化されたバイナリデータを取得できます(一時的にメモリに保存されます)。

于 2008-11-11T20:05:46.450 に答える