public static void TestEncrypt() { ICrypto crypto = new V2AesCrypto(new SymmetricKey(testKey), new SymmetricIV(testPlaintext), 0); byte[] zeroPlain = new byte[testCipertext.Length]; byte[] cipherText = crypto.Encrypt(zeroPlain); Assert.That(cipherText.IsEquivalentTo(testCipertext)); }
public static void TestEncryptPartialBlock() { ICrypto crypto = new V2AesCrypto(new SymmetricKey(testKey), new SymmetricIV(testPlaintext), 3); byte[] zeroPlain = new byte[5]; byte[] cipherText = crypto.Encrypt(zeroPlain); byte[] partOfTestCipherText = new byte[5]; Array.Copy(testCipertext, 3, partOfTestCipherText, 0, 5); Assert.That(cipherText.IsEquivalentTo(partOfTestCipherText)); }
public static void TestExtensions_DecryptToBadArgumentsCausingEarlyException(CryptoImplementation cryptoImplementation) { SetupAssembly.AssemblySetupCrypto(cryptoImplementation); Stream nullStream = null; ICryptoTransform nullEncryptor = null; ICryptoTransform encryptor = new V2AesCrypto(SymmetricKey.Zero256, SymmetricIV.Zero128, 0).DecryptingTransform(); Assert.Throws <ArgumentNullException>(() => nullStream.DecryptTo(Stream.Null, encryptor, true)); Assert.Throws <ArgumentNullException>(() => Stream.Null.DecryptTo(nullStream, encryptor, true)); Assert.Throws <ArgumentNullException>(() => Stream.Null.DecryptTo(Stream.Null, nullEncryptor, true)); }
public static void TestConstructorWithBadArguments() { SymmetricKey nullKey = null; SymmetricKey testKey = new SymmetricKey(128); SymmetricIV testIV = new SymmetricIV(128); ICrypto crypto = null; Assert.Throws <ArgumentNullException>(() => crypto = new V2AesCrypto(nullKey, testIV, 0)); testKey = new SymmetricKey(64); Assert.Throws <ArgumentException>(() => crypto = new V2AesCrypto(testKey, testIV, 0)); testKey = new SymmetricKey(256); testIV = new SymmetricIV(64); Assert.Throws <ArgumentException>(() => crypto = new V2AesCrypto(testKey, testIV, 0)); testIV = new SymmetricIV(128); Assert.DoesNotThrow(() => crypto = new V2AesCrypto(testKey, testIV, 0)); Assert.That(crypto, Is.Not.Null); }
public static void TestEncryptSeveralBlocks() { byte[] iv = new byte[16]; Array.Copy(nistInitCounter, iv, 8); long blockCounter = nistInitCounter.GetBigEndianValue(8, 8); ICrypto crypto; crypto = new V2AesCrypto(new SymmetricKey(nistKey), new SymmetricIV(iv), blockCounter << 4); byte[] cipherText1 = crypto.Encrypt(nistPlaintext1); Assert.That(cipherText1.IsEquivalentTo(nistCiphertext1)); crypto = new V2AesCrypto(new SymmetricKey(nistKey), new SymmetricIV(iv), (++blockCounter) << 4); byte[] cipherText2 = crypto.Encrypt(nistPlaintext2); Assert.That(cipherText2.IsEquivalentTo(nistCiphertext2)); crypto = new V2AesCrypto(new SymmetricKey(nistKey), new SymmetricIV(iv), (++blockCounter) << 4); byte[] cipherText3 = crypto.Encrypt(nistPlaintext3); Assert.That(cipherText3.IsEquivalentTo(nistCiphertext3)); crypto = new V2AesCrypto(new SymmetricKey(nistKey), new SymmetricIV(iv), (++blockCounter) << 4); byte[] cipherText4 = crypto.Encrypt(nistPlaintext4); Assert.That(cipherText4.IsEquivalentTo(nistCiphertext4)); }