简体   繁体   中英

Aes Encryption in C# Decrypt using other IV

They say you can decrypt the data by using the same secret key but another Initialization Vector, How to achieve that one? Example: My IV for encryption is as follows byte[] bytes = {12,12,5,12,32,62,91,16,89,92,17,72,45,52,13,42}; but for my Decryption is random IV that is 16bytes in length.

You need to call SymmetricAlgorithm.CreateDecryptor() with the same IV that was used for encrypting.

Quoting from the docs :

The SymmetricAlgorithm.CreateDecryptor method from the Aes instance is passed the IV value and the same key that was used for encryption.

Code sample, also from docs page:

Aes aes = Aes.Create();
CryptoStream cryptStream = new CryptoStream(
    fileStream,
    aes.CreateDecryptor(key, iv),
    CryptoStreamMode.Read
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM