Esempio n. 1
0
 public void Decrypt_throws_on_invalid_iv_length()
 {
     Assert.That(
         () => AesGcm.Decrypt(key: new byte[32],
                              ciphertext: new byte[16],
                              iv: new byte[13],
                              authData: new byte[0]),
         ExceptionsTest.ThrowsInvalidOpeationWithMessage("iv must"));
 }
Esempio n. 2
0
 public void Encrypt_throws_on_invalid_key_length()
 {
     Assert.That(
         () => AesGcm.Encrypt(key: new byte[13],
                              plaintext: new byte[16],
                              iv: new byte[12],
                              authData: new byte[0]),
         ExceptionsTest.ThrowsInvalidOpeationWithMessage("key must"));
 }
Esempio n. 3
0
 public void Decrypt_throws_on_modified_ciphertext()
 {
     foreach (var i in TestCases)
     {
         // Change the first byte of the ciphertext
         var modified = Modified(i.CiphertextWithTag, 0);
         Assert.That(() => AesGcm.Decrypt(i.Key, modified, i.Iv, i.AuthData),
                     ExceptionsTest.ThrowsInvalidOpeationWithMessage("auth tag"));
     }
 }
Esempio n. 4
0
        public void CombineWith_throws_on_incorrect_length()
        {
            var bytes = new[]
            {
                "",
                "A",
                "All your base are belong to us",
                "All your base are belong to us!",
                "All your base are belong to us!!!",
            };

            foreach (var b in bytes)
                Assert.That(() => Key.CombineWith(b.ToBytes()),
                            ExceptionsTest.ThrowsInvalidOpeationWithMessage("hash function"));
        }
Esempio n. 5
0
        public void Parse_throws_on_invalid_key_format()
        {
            var keys = new[]
            {
                "", // Too short for format
                "A", // Too short for format
                "A2", // Too short
                "A3", // Too short
                "A2-RTN9SA-DY9445Y5FF96X6E7B5GPFA95", // Too short for A2
                "A2-RTN9SA-DY9445Y5FF96X6E7B5GPFA95R9", // Too long for A2
                "A3-RTN9SA-DY9445Y5FF96X6E7B5GPFA95R", // Too short for A3
                "A3-RTN9SA-DY9445Y5FF96X6E7B5GPFA95R99", // Too long for A3
                "A3-RTN9SA-DY9445Y-FF96X6E7B-GPFA95R9" // Too short for A3 after removing of "-"
            };

            foreach (var key in keys)
                Assert.That(() => AccountKey.Parse(key),
                            ExceptionsTest.ThrowsInvalidOpeationWithMessage("Invalid account key"));
        }
Esempio n. 6
0
        public void ValidateB_throws_on_failed_validation()
        {
            var b = ("0FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA" +
                     "63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C24" +
                     "5E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F241" +
                     "17C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5" +
                     "F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C0" +
                     "8CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C" +
                     "9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170" +
                     "D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C" +
                     "7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D876027" +
                     "33EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3" +
                     "143DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D788719A10BDBA5B2699C3271" +
                     "86AF4E23C1A946834B6150BDA2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA" +
                     "6287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED1F612970CEE2D7AFB81BDD7" +
                     "62170481CD0069127D5B05AA993B4EA988D8FDDC186FFB7DC90A6C08F4DF435C93406319" +
                     "9FFFFFFFFFFFFFFFF").ToBigInt();

            Assert.That(() => Srp.ValidateB(b),
                        ExceptionsTest.ThrowsInvalidOpeationWithMessage("validation failed"));
        }
Esempio n. 7
0
 public void ExchangeAForB_throws_on_mismatching_session_id()
 {
     Assert.That(() => PerformExchange("exchange-a-for-b-response", "incorrect-session-id"),
                 ExceptionsTest.ThrowsInvalidOpeationWithMessage("ID doesn't match"));
 }
Esempio n. 8
0
 public void String_DecodeHex_throws_on_non_hex_characters()
 {
     Assert.That(() => "xz".DecodeHex(),
                 ExceptionsTest.ThrowsInvalidOpeationWithMessage(
                     "input contains invalid characters"));
 }
Esempio n. 9
0
 public void String_DecodeHex_throws_on_odd_length()
 {
     Assert.That(() => "0".DecodeHex(),
                 ExceptionsTest.ThrowsInvalidOpeationWithMessage(
                     "input length must be multiple of 2"));
 }