Beispiel #1
0
        public void CryptoBoxOpenAfternm_Decryption_Should_Success()
        {
            //Arrange
            String expectedMessage = "test";

            Byte[] bMessage = Encoding.UTF8.GetBytes(expectedMessage);
            Byte[] pk       = new Byte[TweetNaCl.BoxPublicKeyBytes];
            Byte[] sk       = new Byte[TweetNaCl.BoxSecretKeyBytes];
            Byte[] nonce    = new Byte[TweetNaCl.BoxNonceBytes];

            pk = TweetNaCl.CryptoBoxKeypair(sk);
            TweetNaCl.RandomBytes(nonce);
            var k = TweetNaCl.CryptoBoxBeforenm(pk, sk);

            //Act
            var encMessage = TweetNaCl.CryptoBoxAfternm(bMessage, nonce, k);
            var decMessage = TweetNaCl.CryptoBoxOpenAfternm(encMessage, nonce, k);

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

            var resultMessage = Encoding.ASCII.GetString(decMessage);

            Assert.AreEqual(resultMessage, expectedMessage, "decryption failed.");
        }