private static bool TestKeyGeneration()
{
try
{
using (AesCryptoServiceProvider aes = new AesCryptoServiceProvider())
{
// Try creating the other sized keys
aes.KeySize = 128;
if (aes.Key.Size != 128)
return false;
// Make sure consecutive reads don't change the key
aes.GenerateKey();
byte[] read1 = aes.Key.ExportKey(true);
byte[] read2 = aes.Key.ExportKey(true);
if (!CompareBytes(read1, read2))
return false;
}
return true;
}
catch
{
return false;
}
}