コード例 #1
0
        public void CryptoSecretBoxOpen_Decryption_Should_Success()
        {
            //Arrange
            String message = "test";

            Byte[] bMessage = Encoding.UTF8.GetBytes(message);
            Byte[] sk       = new Byte[TweetNaCl.SecretBoxKeyBytes];
            Byte[] nonce    = new Byte[TweetNaCl.SecretBoxNonceBytes];

            TweetNaCl.RandomBytes(sk);
            TweetNaCl.RandomBytes(nonce);

            var encMessage = TweetNaCl.CryptoSecretBox(bMessage, nonce, sk);

            //Act
            var decMessage = TweetNaCl.CryptoSecretBoxOpen(encMessage, nonce, sk);

            Assert.AreEqual(decMessage.Length, bMessage.Length, "decryption failed.");
            Assert.AreEqual(decMessage, bMessage, "decryption failed.");
        }