public void CleanRoundtripBytes(SymmetricCryptoManager testCryptoManager)
        {
            var rng  = new Random();
            var data = new byte[1064 * 1064];
            var iv   = new byte[64];
            var key  = new byte[64];

            rng.NextBytes(data);
            rng.NextBytes(iv);
            rng.NextBytes(key);

            byte[] encryptedBytes = testCryptoManager.EncryptBytes(data, key.Take(testCryptoManager.KeySize / 8).ToArray(), iv);
            byte[] decryptedBytes = testCryptoManager.DecryptBytes(encryptedBytes, key.Take(testCryptoManager.KeySize / 8).ToArray(), iv);

            Assert.True(data.SequenceEqual(decryptedBytes));
        }
        public void TestBadData(SymmetricCryptoManager testCryptoManager)
        {
            var rng     = new Random();
            var iv      = new byte[64];
            var key     = new byte[64];
            var badData = new byte[1064 * 1064];

            rng.NextBytes(iv);
            rng.NextBytes(key);
            rng.NextBytes(badData);

            var shouldFail = new Action(() =>
            {
                _ = testCryptoManager.DecryptBytes(badData, key.Take(testCryptoManager.KeySize / 8).ToArray(), iv);
            });

            Assert.Throws <CryptographicException>(shouldFail);
        }
        public void TestBytesEarlyIv(SymmetricCryptoManager testCryptoManager)
        {
            var rng  = new Random();
            var data = new byte[1064 * 1064];
            var iv   = new byte[64];
            var key  = new byte[64];

            rng.NextBytes(data);
            rng.NextBytes(iv);
            rng.NextBytes(key);

            testCryptoManager.InitializationVector = iv;

            byte[] encryptedData  = testCryptoManager.EncryptBytes(data, key.Take(testCryptoManager.KeySize / 8).ToArray());
            byte[] decryptedBytes = testCryptoManager.DecryptBytes(encryptedData, key.Take(testCryptoManager.KeySize / 8).ToArray());

            Assert.True(data.SequenceEqual(decryptedBytes));
        }
Exemplo n.º 4
0
 /// <inheritdoc />
 /// <summary>
 /// Creates a new instance with of
 /// BufferSizeChangedEventArgs
 /// </summary>
 /// <param name="newValue">The new chunk value</param>
 /// <param name="sender">The sending object</param>
 public BufferSizeChangedEventArgs(int newValue, SymmetricCryptoManager sender)
 {
     this.NewValue = newValue;
     this.Sender   = sender;
 }