Je travaille sur une méthode de chiffrement de base. J'utilise RijndaelManaged. J'ai reçu ce code il y a longtemps, mais je ne me souviens plus où.Le vecteur d'initialisation spécifié (IV) ne correspond pas à la taille du bloc pour cet algorithme
J'avais mon code qui fonctionnait avant, mais quelque chose a changé et je n'arrive pas à le comprendre. Lorsque j'exécute mon code, j'obtiens l'erreur suivante:
vecteur d'initialisation indiquée (IV) ne correspond pas à la taille du bloc pour cet algorithme .
Voici mon code:
string textToEncrypt = "TEST STRING";
int keySize = 256;
string hashAlgorithm = "SHA1";
string passPhrase = "AH!PSB0%FGHR$";
string saltValue = "LRT%YUR#[email protected]";
string initVector = "HR$2pIjHR$2pIj";
byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector);
byte[] saltValueBytes = Encoding.ASCII.GetBytes(saltValue);
byte[] plainTextBytes = Encoding.UTF8.GetBytes(textToEncrypt);
PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, saltValueBytes, hashAlgorithm, 2);
byte[] keyBytes = password.GetBytes(keySize/8);
RijndaelManaged symmetricKey = new RijndaelManaged();
symmetricKey.Mode = CipherMode.CBC;
ICryptoTransform encryptor = symmetricKey.CreateEncryptor(keyBytes,initVectorBytes);
MemoryStream memoryStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(memoryStream,encryptor,CryptoStreamMode.Write);
cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
cryptoStream.FlushFinalBlock();
byte[] cipherTextBytes = memoryStream.ToArray();
memoryStream.Close();
cryptoStream.Close();
string cipherText = Convert.ToBase64String(cipherTextBytes);
Toute aide sera appréciée.
Oh mon dieu, c'était tout! Merci beaucoup pour l'aide. –