public void XSalsa20Test() { var key = StreamEncryption.GenerateKey(); var nonce = StreamEncryption.GenerateNonce(); string message = "Hello, World!"; var cipherText = StreamEncryption.Encrypt(message, nonce, key); var decrypted = StreamEncryption.Decrypt(cipherText, nonce, key); Assert.AreEqual(message, System.Text.Encoding.UTF8.GetString(decrypted)); byte[] byteMessage = System.Text.Encoding.UTF8.GetBytes(message); cipherText = StreamEncryption.Encrypt(byteMessage, nonce, key); decrypted = StreamEncryption.Decrypt(cipherText, nonce, key); Assert.AreEqual(Convert.ToBase64String(byteMessage), Convert.ToBase64String(decrypted)); cipherText = StreamEncryption.EncryptXSalsa20(message, nonce, key); decrypted = StreamEncryption.DecryptXSalsa20(cipherText, nonce, key); Assert.AreEqual(message, System.Text.Encoding.UTF8.GetString(decrypted)); byteMessage = System.Text.Encoding.UTF8.GetBytes(message); cipherText = StreamEncryption.EncryptXSalsa20(byteMessage, nonce, key); decrypted = StreamEncryption.DecryptXSalsa20(cipherText, nonce, key); Assert.AreEqual(Convert.ToBase64String(byteMessage), Convert.ToBase64String(decrypted)); }
public void TestGenerateNonce() { Assert.AreEqual(24, StreamEncryption.GenerateNonce().Length); }