Beispiel #1
0
        public void TestAesNonRepeating(string subDir, string nestedDir)
        {
            var subPath = Util.TestDataPath(TEST_DATA, subDir, nestedDir);

            using (var crypter = new Crypter(subPath))
            {
                var cipher = crypter.Encrypt(input);
                var cipher2 = crypter.Encrypt(input);
                Expect(cipher, Is.Not.EqualTo(cipher2));
            }
        }
Beispiel #2
0
        public void AESTest(
            [Values(2048)] int datasize,
            [Values(128, 192, 256)] int keysize,
            [Values("AES", "STDNET40_AES", "C#_AES_AEAD")] string alg
            )
        {
            KeyType type = alg;
            var key = Key.Generate(type, keysize);
            using (var ks = new ImportedKeySet(key, KeyPurpose.DecryptAndEncrypt, "Test"))
            using (var crypter = new Crypter(ks))
            {
                var watchEncrypt = new System.Diagnostics.Stopwatch();
                var watchDecrypt = new System.Diagnostics.Stopwatch();
                for (int i = 0; i < iterations; i++)
                {
                    var input = new byte[datasize];

                    watchEncrypt.Start();
                    var output = crypter.Encrypt(input);
                    watchEncrypt.Stop();

                    watchDecrypt.Start();
                    var result = crypter.Decrypt(output);
                    watchDecrypt.Stop();

                    Expect(result, Is.EqualTo(input));
                }

                Console.WriteLine(String.Format("{3}-{4},{2}\t\tEncryption Total:{0},\tThroughput:{1:#,##0.00} MB/S",
                                                watchEncrypt.Elapsed,
                                                (datasize*iterations*1000m)/
                                                (1024m*1024m*watchEncrypt.ElapsedMilliseconds),
                                                datasize,
                                                alg,
                                                keysize
                                      ));
                Console.WriteLine(String.Format("{3}-{4},{2}\t\tDecryption Total:{0},\tThroughput:{1:#,##0.00} MB/S",
                                                watchDecrypt.Elapsed,
                                                (datasize*iterations*1000m)/
                                                (1024m*1024m*watchDecrypt.ElapsedMilliseconds),
                                                datasize,
                                                alg,
                                                keysize
                                      ));
            }
        }
Beispiel #3
0
        public void TestBadCipherText(string subDir, string nestedDir)
        {
            var subPath = Util.TestDataPath(TEST_DATA, subDir, nestedDir);

            using (var crypter = new Crypter(subPath))
            {
                Expect(() => crypter.Decrypt(new byte[0]), Throws.TypeOf<InvalidCryptoDataException>());
                byte[] ciphertext = crypter.Encrypt(inputBytes);
                // Munge the key hash
                ciphertext[1] ^= 44;
                Expect(() => crypter.Decrypt(ciphertext), Throws.TypeOf<InvalidCryptoDataException>());
                //restore
                ciphertext[1] ^= 44;
                // Munge the ciphertext
                ciphertext[15] ^= 39;
                Expect(() => crypter.Decrypt(ciphertext), Throws.TypeOf<InvalidCryptoDataException>());
            }
        }
Beispiel #4
0
 public void TestShortEncryptAndDecrypt(string subDir, string nestedDir)
 {
     var subPath = Util.TestDataPath(TEST_DATA, subDir, nestedDir);
     using (var crypter = new Crypter(subPath))
     {
         for (int i = 0; i < 32; i++)
         {
             var letters = Enumerable.Repeat('a', i).ToArray();
             var each = new String(letters);
             var ciphertext = crypter.Encrypt(each);
             var decrypted = crypter.Decrypt(ciphertext);
             Expect(decrypted, Is.EqualTo(each), "Length:" + i);
         }
     }
 }
Beispiel #5
0
        public void TestEncryptDecryptCompression(CompressionType compression)
        {
            var subPath = Util.TestDataPath(TEST_DATA, "aes");

            using (var crypter = new Crypter(subPath) {Compression = compression})
            {
                var cipher = crypter.Encrypt(input);
                var decrypt = crypter.Decrypt(cipher);
                Expect(decrypt, Is.EqualTo(input));
                using (var crypter2 = new Crypter(subPath))
                {
                    var decrypt2 = crypter2.Decrypt(cipher);
                    Expect(decrypt2, Is.Not.EqualTo(input));
                }

                var ciphertiny = crypter.Encrypt(bigInput);
                //large array of zeros will compress down a lot
                Expect(ciphertiny.Length, Is.LessThan(bigInput.Length));
                var big = crypter.Decrypt(ciphertiny);
                Expect(big, Is.EqualTo(bigInput));
            }
        }
Beispiel #6
0
        public void TestEncryptDecrypt(String subDir, string nestedDir)
        {
            var subPath = Util.TestDataPath(TEST_DATA, subDir, nestedDir);

            using (var crypter = new Crypter(subPath))
            {
                var cipher = crypter.Encrypt(input);
                var decrypt = crypter.Decrypt(cipher);
                Expect(decrypt, Is.EqualTo(input));
            }
        }