Problème de chiffrement avec AES : argument (apparemment) null
Bonjour,
J'ai implémenté une classe pour faire le déchiffrement en AES qui se présente comme ceci:
Code:
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| public string decryptWithAES(string cypherText, string passPhrase, byte[] randomNumber)
{
string decryptedData = null;
AesCryptoServiceProvider aes;
try
{
aes = new AesCryptoServiceProvider();
}
catch (System.PlatformNotSupportedException PlatNotSupExc)
{
throw;
}
try
{
aes.BlockSize = 128;
aes.KeySize = 256;
aes.Mode = CipherMode.CFB;
aes.Padding = PaddingMode.PKCS7;
}
catch (System.Security.Cryptography.CryptographicException CryptoExc)
{
throw;
}
Rfc2898DeriveBytes derivedBytes;
try
{
derivedBytes = new Rfc2898DeriveBytes(passPhrase, randomNumber, 20000);
}
catch (System.ArgumentNullException ArgNullExc)
{
throw;
}
catch (System.ArgumentException ArgExc)
{
throw;
}
try
{
aes.Key = derivedBytes.GetBytes(32);
aes.IV = derivedBytes.GetBytes(16);
}
catch (System.Security.Cryptography.CryptographicException CryptoExc)
{
throw;
}
catch (System.ArgumentNullException ArgNullExc)
{
throw;
}
catch (System.ArgumentOutOfRangeException ArgOutOfRangeExc)
{
throw;
}
byte[] myData;
try
{
myData = System.Text.Encoding.UTF8.GetBytes(cypherText);
}
catch (System.ArgumentNullException ArgNullExc)
{
throw;
}
catch (System.Text.EncoderFallbackException EncFallBackExc)
{
throw;
}
try
{
ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV);
using (MemoryStream msDecrypt = new MemoryStream(myData))
{
using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
{
using (StreamReader swDecrypt = new StreamReader(csDecrypt))
{
decryptedData = swDecrypt.ReadToEnd();
}
csDecrypt.Close();
}
msDecrypt.Close();
}
}
catch (System.OutOfMemoryException OutOfMemExc)
{
throw;
}
catch (System.IO.IOException IOExc)
{
throw;
}
catch (System.ArgumentNullException ArgNullExc)
{
throw;
}
catch (System.ArgumentException ArgExc)
{
throw;
}
return decryptedData;
} |
J'ai une erreur lorsque j'arrive dans ce bloque-ci :
Code:
1 2 3 4
| using (StreamReader swDecrypt = new StreamReader(csDecrypt))
{
decryptedData = swDecrypt.ReadToEnd();
} |
Ou j'obtiens l'erreur suivante:
Code:
Value cannot be null. Parameter name: inputBuffer
Est-ce que vous avez une idée de l'erreur? Serait-il possible qu'AES ait une limitation de la taille du cipher? Car je ne vois absolument pas ou est mon erreur :/
Merci bien :)
L.