public static void Test(string[] testVector) { if (testVector == null) { return; } var key = testVector[0]; var iv = testVector[1]; var pt = testVector[2]; var aad = testVector[3]; var ct = testVector[4]; var tag = testVector[5]; var a = new Aes256Gcm(); using (var k = Key.Import(a, key.DecodeHex(), KeyBlobFormat.RawSymmetricKey)) { var n = iv.DecodeHex(); var p = pt.DecodeHex(); var d = aad.DecodeHex(); var expected = (ct + tag).DecodeHex(); var actual = a.Encrypt(k, n, d, p); Assert.Equal(expected, actual); Assert.Equal(p, a.Decrypt(k, n, d, expected)); } }
public static void Properties() { var a = new Aes256Gcm(); Assert.Equal(32, a.KeySize); Assert.Equal(12, a.NonceSize); Assert.Equal(16, a.TagSize); }
public static void Test(string[] testVector) { if (testVector == null) { return; } var key = testVector[0]; var iv = testVector[1]; var ct = testVector[2]; var aad = testVector[3]; var tag = testVector[4]; var pt = testVector[5]; var fail = bool.Parse(testVector[6]); var a = new Aes256Gcm(); using (var k = Key.Import(a, key.DecodeHex(), KeyBlobFormat.RawSymmetricKey)) { var n = iv.DecodeHex(); var c = (ct + tag).DecodeHex(); var d = aad.DecodeHex(); var expected = pt.DecodeHex(); var actual = new byte[c.Length - a.TagSize]; if (fail) { Assert.False(a.TryDecrypt(k, n, d, c, actual)); } else { Assert.True(a.TryDecrypt(k, n, d, c, actual)); Assert.Equal(expected, actual); } } }