public EncryptionHelper()
 {
     buffer = new byte[1000];
     NativeLibsodium.sodium_init();
     _SetKeys();
     //GenerateNewKey();
 }
Example #2
0
    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;
    }
Example #3
0
        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);
        }
Example #4
0
    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));
    }
Example #5
0
 private void Awake()
 {
     NativeLibsodium.sodium_init();
     SetNetworkInfo(networkInfo);
 }