Beispiel #1
0
        public void Decrypt_throws_on_mismatching_mac()
        {
            var key        = "SLBgfXoityZsz4ZWvpEPULPZMYGH6vSqh3PXTe5DmyM=".Decode64();
            var iv         = "XZ2vMa5oFCcp7BUAfPowvA==".Decode64();
            var ciphertext = "1/GDPwJWo+2Iacio0UkRfR0zXXUufGjMIxD+y/A/YfQPKKep69B0nfbueqZJ1nA1pv15qVounBVJLhetVMGW7mKSxdVtTYObe0Uiqm/C9/s=".Decode64();
            var mac        = "mismatching MAC, mismatching MAC".ToBytes();
            var cs         = new CipherString(mode: CipherMode.Aes256CbcHmacSha256, iv: iv, ciphertext: ciphertext, mac: mac);

            Exceptions.AssertThrowsCrypto(() => cs.Decrypt(key), "MAC doesn't match");
        }
 public void DecryptAes256_throws_on_invalid_input(string ciphertext, string iv, string key)
 {
     foreach (var cipherMode in new[] { CipherMode.ECB, CipherMode.CBC })
     {
         foreach (var padding in new[] { PaddingMode.None, PaddingMode.PKCS7 })
         {
             Exceptions.AssertThrowsCrypto(() => Crypto.DecryptAes256(ciphertext.ToBytes(),
                                                                      iv.ToBytes(),
                                                                      key.ToBytes(),
                                                                      cipherMode,
                                                                      padding));
         }
     }
 }
Beispiel #3
0
 static void Check(byte[] ciphertext, byte[] nonce, byte[] key)
 {
     Exceptions.AssertThrowsCrypto(() => Crypto.DecryptXChaCha20Poly1305(ciphertext, nonce, key),
                                   "Tag doesn't match, the data is corrupted or the key is incorrect");
 }