Note that there are some explanatory texts on larger screens.

plurals
  1. POAES Decryption Exception change
    text
    copied!<p>I have an AES Cryptography wrapper and unit tests that has been working for over a year. Now after installing VS 2012 (or maybe an update to .net Framework 4) the unit tests do not pass. The streamreader block was throwing a CryptographicException when I passed in a bad pass but is not throwing a ArgumentNullException.</p> <p>The code is up at. <a href="https://github.com/jnaus/Cryptography" rel="nofollow">https://github.com/jnaus/Cryptography</a></p> <p><br/> Here is the unit test that now does not work. (BadSaltTest has the same problem)</p> <pre><code>[TestMethod] [ExpectedException(typeof(CryptographicException), "Bad password was inappropriately allowed")] public void BadPasswordTest() { var cipherText = EncryptString(); var decryptedText = AESCryptography.DecryptStringAES (cipherText,"A bad password", salt); } </code></pre> <p>Test Result: Test method CryptographyTest.AESTest.BadPasswordTest threw exception System.ArgumentNullException, but exception System.Security.Cryptography.CryptographicException was expected. Exception message: System.ArgumentNullException: Value cannot be null. Parameter name: inputBuffer</p> <p>Decrypt code.</p> <pre><code>public static string DecryptStringAES(string cipherText, string password, byte[] salt) { RijndaelManaged aesAlg = null; string plaintext = null; try { // generate the key from the shared secret and the salt Rfc2898DeriveBytes key = new Rfc2898DeriveBytes(password, salt); // Create a RijndaelManaged object // with the specified key and IV. aesAlg = new RijndaelManaged(); aesAlg.Key = key.GetBytes(aesAlg.KeySize/8); aesAlg.IV = key.GetBytes(aesAlg.BlockSize/8); // Create a decrytor to perform the stream transform. ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV); // Create the streams used for decryption. byte[] bytes = Convert.FromBase64String(cipherText); using (MemoryStream msDecrypt = new MemoryStream(bytes)) { using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)) { //StreamReader now gives ArgumentNullException using (StreamReader srDecrypt = new StreamReader(csDecrypt)) { // Read the decrypted bytes from the decrypting stream // and place them in a string. plaintext = srDecrypt.ReadToEnd(); } } } } finally { // Clear the RijndaelManaged object. if (aesAlg != null) { aesAlg.Clear(); } } return plaintext; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload