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)); }
private void Start() { int x = NativeLibsodium.sodium_init(); Debug.Log(x); const string MESSAGE = "Test message to encrypt"; byte[] nonce = StreamEncryption.GenerateNonceChaCha20(); byte[] key = StreamEncryption.GenerateKey(); //encrypt it byte[] encrypted = StreamEncryption.EncryptChaCha20(MESSAGE, nonce, key); //decrypt it byte[] decrypted = StreamEncryption.DecryptChaCha20(encrypted, nonce, key); string str_origin = MESSAGE; string str_encrypted = Encoding.UTF8.GetString(encrypted); string str_decrypted = Encoding.UTF8.GetString(decrypted); Debug.Log(str_origin); Debug.Log(str_encrypted); Debug.Log(str_decrypted); txt_origin.text = str_origin; txt_encrypted.text = str_encrypted; txt_decrypted.text = str_decrypted; }
public void Stream_Encryption_Basic() { var nonce = StreamEncryption.GenerateNonceChaCha20(); var key = StreamEncryption.GenerateKey(); var messageString = "Test message to encrypt"; var encrypted = StreamEncryption.EncryptChaCha20(messageString, nonce, key); var decrypted = StreamEncryption.DecryptChaCha20(encrypted, nonce, key); Assert.AreEqual(messageString, Encoding.UTF8.GetString(decrypted)); }
public void TestChaCha20() { int x = NativeLibsodium.sodium_init(); Assert.True(x == 0 || x == 1); const string MESSAGE = "Test message to encrypt"; byte[] nonce = StreamEncryption.GenerateNonceChaCha20(); byte[] key = StreamEncryption.GenerateKey(); //encrypt it byte[] encrypted = StreamEncryption.EncryptChaCha20(MESSAGE, nonce, key); //decrypt it byte[] decrypted = StreamEncryption.DecryptChaCha20(encrypted, nonce, key); Assert.AreEqual(MESSAGE, decrypted); }
private void Start() { int x = NativeLibsodium.sodium_init(); Debug.Log(x); const string MESSAGE = "Test message to encrypt"; byte[] nonce = StreamEncryption.GenerateNonceChaCha20(); byte[] key = StreamEncryption.GenerateKey(); //encrypt it byte[] encrypted = StreamEncryption.EncryptChaCha20(MESSAGE, nonce, key); //decrypt it byte[] decrypted = StreamEncryption.DecryptChaCha20(encrypted, nonce, key); Debug.Log(MESSAGE); Debug.Log(Encoding.UTF8.GetString(encrypted)); Debug.Log(Encoding.UTF8.GetString(decrypted)); }
public void GenerateNewKey() { _crypteKey = StreamEncryption.GenerateKey(); // NativeLibsodium.crypto_sign_keypair( _publicKey, _privateKey ); }
public void TestGenerateKey() { Assert.AreEqual(32, StreamEncryption.GenerateKey().Length); }