Bonjour,
J'ai crée une fonction de déchiffrement du mot de passe avec la fonction suivante qui utilise l'algorithme de cryptographie AES
dont voici le code :
Voici que j'obtiens une erreur au niveau de cette instruction :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 public static string DecryptStringFromBytes_Aes(byte[] cipherText, byte[] Key, byte[] IV) { // Check arguments. if (cipherText == null || cipherText.Length <= 0) throw new ArgumentNullException("cipherText"); if (Key == null || Key.Length <= 0) throw new ArgumentNullException("Key"); if (IV == null || IV.Length <= 0) throw new ArgumentNullException("IV"); // Declare the string used to hold // the decrypted text. string password_decrypte = null; // Create an AesCryptoServiceProvider object // with the specified key and IV. using (AesCryptoServiceProvider aesAlg = new AesCryptoServiceProvider()) { aesAlg.Key = Key; aesAlg.IV = IV; // Create a decrytor to perform the stream transform. ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV); // Create the streams used for decryption. using (MemoryStream msDecrypt = new MemoryStream(cipherText)) { using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)) { using (StreamReader srDecrypt = new StreamReader(csDecrypt)) { // Read the decrypted bytes from the decrypting stream // and place them in a string. password_decrypte = srDecrypt.ReadToEnd(); } } } } return password_decrypte; }
srDecrypt.ReadToEnd();
dont voici le texte
J'ai lu le post suivant http://www.developpez.net/forums/d13...aremment-null/ qui parle de mode du cipher
Une erreur est survenue Les données d'entrée ne constituent pas un bloc complet.Son détail est à System.Security.Cryptography.CapiSymmetricAlgorithm.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount) à System.Security.Cryptography.CryptoStream.FlushFinalBlock()
J'ai ajouté cette instruction à la fonction DecryptStringFromBytes_Aes(byte[] cipherText, byte[] Key, byte[] IV) au niveau du using , comme conseillé par la personne qui a résolu son pb dans le post , mais sans resultat, le msg d'erreur étant le même.
Si vous avez une suggestion à me faire, je vous en remercie beaucoup car je tourne un peu en rond avec cette situation.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 using (AesCryptoServiceProvider aesAlg = new AesCryptoServiceProvider()) { aesAlg.Mode = CipherMode.CFB; aesAlg.Key = Key; aesAlg.IV = IV;
Bien cordialement.
new_wave
Partager