public static bool TestClear(Aes aes) { byte[] key = aes.Key; byte[] IV = aes.IV; try { aes.Clear(); // AESCSP will throw an ObjectDisposedException after class is used after Clear is called. This is reasonable behavior even though // it's different than DESCSP, etc. If the class is still usable (ie the managed version) then make sure the key and IV are not // the same. // if (CompareBytes(aes.Key, key)) { Console.WriteLine("Error - key not reset after Clear"); return false; } if (CompareBytes(aes.IV, IV)) { Console.WriteLine("Error - IV not reset after Clear"); return false; } } catch (ObjectDisposedException) { } return true; }