コード例 #1
0
ファイル: XChaCha20Tests.cs プロジェクト: orion6dev/NaCl.Core
        public void EncryptDecryptLongMessagesWithNonceTest()
        {
            var rnd = new Random();

            var dataSize = 16;

            while (dataSize <= (1 << 24))
            {
                var plaintext = new byte[dataSize];
                rnd.NextBytes(plaintext);

                var key = new byte[Snuffle.KEY_SIZE_IN_BYTES];
                rnd.NextBytes(key);

                var cipher = new XChaCha20(key, 0);

                var nonce = new byte[cipher.NonceSizeInBytes()];
                rnd.NextBytes(nonce);

                var ciphertext = cipher.Encrypt(plaintext, nonce);
                var decrypted  = cipher.Decrypt(ciphertext, nonce);

                //Assert.AreEqual(plaintext, decrypted);
                Assert.IsTrue(CryptoBytes.ConstantTimeEquals(plaintext, decrypted));
                dataSize += 5 * dataSize / 11;
            }
        }
コード例 #2
0
ファイル: XChaCha20Tests.cs プロジェクト: orion6dev/NaCl.Core
        public void XChaCha20BlockWhenLengthIsInvalidFails()
        {
            // Arrange
            var key = new byte[Snuffle.KEY_SIZE_IN_BYTES];

            var cipher = new XChaCha20(key, 0);
            var nonce  = new byte[cipher.NonceSizeInBytes() + TestHelpers.ReturnRandomPositiveNegative()];
            var block  = new byte[0];

            // Act & Assert
            Assert.Throws <CryptographicException>(() => cipher.ProcessKeyStreamBlock(nonce, 0, block));
        }
コード例 #3
0
ファイル: XChaCha20Tests.cs プロジェクト: orion6dev/NaCl.Core
        public void DecryptWhenNonceLengthIsInvalidFails()
        {
            // Arrange
            var cipher = new XChaCha20(new byte[Snuffle.KEY_SIZE_IN_BYTES], 0);

            // Act & Assert
            Assert.Throws <CryptographicException>(() => cipher.Decrypt(new byte[0], new byte[cipher.NonceSizeInBytes() + TestHelpers.ReturnRandomPositiveNegative()]), EXCEPTION_MESSAGE_NONCE_LENGTH);
        }