Advanced _Stream cipher (XSalsa20) - Chewhern/ASodium GitHub Wiki

For detailed documentation, kindly refer to official libsodium.

There's a straight encrypt and decrypt variant, I know what it does.. but I have no idea how to explain it in this documentation.. (not quite sure if it's clear or vague or wrong)

Let's assume you have 3 messages, each with 32 bytes respectively, the initial counter of the stream cipher is 1, it will produce a temporary key which we called as A, A will then be XOR with Message A to get cipher text or vice versa. For Message B and C, the initial counter will be 2 and 3 which will produce temporary Key B and C.

Straight encrypt or decrypt refers to you adjust the initial counter to produce a different key to XOR with your message/data.

(https://github.com/Chewhern/ASodium/blob/main/Source/SodiumStreamCipherSalsa20.cs)

Salsa20 encryption and decryption

Initial Functions

public static Byte[] XSalsa20Encrypt(Byte[] Message, Byte[] Nonce, Byte[] Key,Boolean ClearKey=false)
public static Byte[] XSalsa20Decrypt(Byte[] CipherText,Byte[] Nonce,Byte[] Key,Boolean ClearKey=false)

Example Code

Byte[] RandomMessage = SodiumRNG.GetRandomBytes(128);
Byte[] Key = SodiumStreamCipherXSalsa20.XSalsa20GenerateKey();
Byte[] Nonce = SodiumStreamCipherXSalsa20.GenerateXSalsa20Nonce();
Byte[] EncryptedMessage = SodiumStreamCipherXSalsa20.XSalsa20Encrypt(RandomMessage, Nonce, Key);
Byte[] DecryptedMessage = SodiumStreamCipherXSalsa20.XSalsa20Decrypt(EncryptedMessage, Nonce, Key);