0
讓e ='密碼',然後我將它轉換爲CryptoStream中的'as9kio0736'。CryptoStream:爲什麼CryptoStreamMode.Write加密和CryptoStreamMode.Read解密?
讓d ='as9kio0736'並將其轉換爲CryptoStream中的密碼。
當我將d變回'密碼'時,爲什麼不考慮在CryptoStream中寫入?
using (MemoryStream msEncrypt = new MemoryStream()) {
using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)) {
using (StreamWriter swEncrypt = new StreamWriter(csEncrypt)) {
swEncrypt.Write(plainText);
}
}
}
using (MemoryStream msDecrypt = new MemoryStream(cipherText)) {
using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)) {
using (StreamReader srDecrypt = new StreamReader(csDecrypt)) {
plaintext = srDecrypt.ReadToEnd();
}
}
}
因爲你寫入,分別從底層流中讀取? – CodeCaster
你寫入密碼流,它加密並將結果寫入MemoryStream(在你的例子中)。您從密碼流中讀取 - 它從MemoryStream中讀取,解密並將結果返回給您。 – Evk