我使用這個樣本代碼:https://msdn.microsoft.com/en-us/library/system.security.cryptography.aesmanaged.aspx相同的加密文本必然導致不同長度
的AESCryptor是我自己的類從上面的MSDN鏈接的原代碼。它僅包含解密/加密方法。
那我怎麼稱呼解密/加密方法:
string plainText1 = "This is my sample plain text";
string plainText2 = "This is my sample plain text";
// Create a new instance of the AesManaged
// class. This generates a new key and initialization
// vector (IV).
using (AesManaged myAes = new AesManaged())
{
// Encrypt the string to an array of bytes.
byte[] encrypted = AESCryptor.EncryptStringToBytes_Aes(plainText1, myAes.Key, myAes.IV);
byte[] encrypted2 = AESCryptor.EncryptStringToBytes_Aes(plainText2, myAes.Key, myAes.IV);
}
我的結果,我想到的是,這兩個(加密和encrypted2)字節數組當然有相同的長度,但被塗抹了「零「所以當我用Base64對字節[]進行編碼時,我得到了不同的字符串。
我該怎麼做?設置myAes.Padding = PaddingMode.Zeros;
沒有幫助。
忘掉來自我的Base64評論。我只是想知道如何獲得2個字節數組與不同的內容相同的純文本。 – Elisabeth
什麼是AESCryptor?就我所知,這不是一個標準的課程......請製作一個簡短但完整的程序來演示問題。 –
這只是我從微軟樣本中實現的類而已。如果你看看msdn示例,你有我的課程。 – Elisabeth