public void CleanRoundtripBytes(SymmetricCryptoManager testCryptoManager) { var rng = new Random(); var data = new byte[1064 * 1064]; var iv = new byte[64]; var key = new byte[64]; rng.NextBytes(data); rng.NextBytes(iv); rng.NextBytes(key); byte[] encryptedBytes = testCryptoManager.EncryptBytes(data, key.Take(testCryptoManager.KeySize / 8).ToArray(), iv); byte[] decryptedBytes = testCryptoManager.DecryptBytes(encryptedBytes, key.Take(testCryptoManager.KeySize / 8).ToArray(), iv); Assert.True(data.SequenceEqual(decryptedBytes)); }
public void TestBadData(SymmetricCryptoManager testCryptoManager) { var rng = new Random(); var iv = new byte[64]; var key = new byte[64]; var badData = new byte[1064 * 1064]; rng.NextBytes(iv); rng.NextBytes(key); rng.NextBytes(badData); var shouldFail = new Action(() => { _ = testCryptoManager.DecryptBytes(badData, key.Take(testCryptoManager.KeySize / 8).ToArray(), iv); }); Assert.Throws <CryptographicException>(shouldFail); }
public void TestBytesEarlyIv(SymmetricCryptoManager testCryptoManager) { var rng = new Random(); var data = new byte[1064 * 1064]; var iv = new byte[64]; var key = new byte[64]; rng.NextBytes(data); rng.NextBytes(iv); rng.NextBytes(key); testCryptoManager.InitializationVector = iv; byte[] encryptedData = testCryptoManager.EncryptBytes(data, key.Take(testCryptoManager.KeySize / 8).ToArray()); byte[] decryptedBytes = testCryptoManager.DecryptBytes(encryptedData, key.Take(testCryptoManager.KeySize / 8).ToArray()); Assert.True(data.SequenceEqual(decryptedBytes)); }