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."); }
public void CryptoBoxAfternm_MessageEncryption_Should_Success() { //Arrange String message = "test"; Byte[] bMessage = Encoding.UTF8.GetBytes(message); Byte[] pk = new Byte[TweetNaCl.BoxPublicKeyBytes]; Byte[] sk = new Byte[TweetNaCl.BoxSecretKeyBytes]; Byte[] nonce = new Byte[TweetNaCl.BoxNonceBytes]; TweetNaCl.RandomBytes(nonce); pk = TweetNaCl.CryptoBoxKeypair(sk); var k = TweetNaCl.CryptoBoxBeforenm(pk, sk); //Act var encMessage = TweetNaCl.CryptoBoxAfternm(bMessage, nonce, k); //Assert Assert.AreEqual(encMessage.Length, bMessage.Length + TweetNaCl.BoxBoxZeroBytes, "encryption failed."); }