BO4E-dotnet.Encryption/SymmetricEncrypter.cs
/// <summary>
///     Encrypt a given plain text and add associated data.
/// </summary>
/// <param name="plainText">UTF-8 encoded string containing the plain text to be encrypted</param>
/// <param name="associatedDataString">max. 16 character long string (not secret)</param>
/// <param name="nonce">unique nonce; not secret but must never be used with the same private key before</param>
/// <returns>the encrypted data as Base64 encoded string</returns>
Encrypt a given plain text and add associated data.
Encrypt a given plain text and add associated data .
private string Encrypt(string plainText, string associatedDataString, byte[] nonce)
        {
            var plainBytes = Encoding.UTF8.GetBytes(plainText);
            var adBytes = Encoding.UTF8.GetBytes(associatedDataString);
            var cipherBytes = SecretAeadChaCha20Poly1305.Encrypt(plainBytes, nonce, _secretKey, adBytes);
            var cipherString = Convert.ToBase64String(cipherBytes);
            return cipherString;
        }
private string Encrypt ( string plainText , string associatedDataString , byte [ ] nonce ) { var plainBytes = Encoding . UTF8 . GetBytes ( plainText ) ; var adBytes = Encoding . UTF8 . GetBytes ( associatedDataString ) ; var cipherBytes = SecretAeadChaCha20Poly1305 . Encrypt ( plainBytes , nonce , _secretKey , adBytes ) ; var cipherString = Convert . ToBase64String ( cipherBytes ) ; return cipherString ; }
Encrypt a given plain text and add associated data.
Encrypt a given plain text and add associated data .
the encrypted data as Base64 encoded string
the encrypted data as Base64 encoded string
plainText
string
UTF-8 encoded string containing the plain text to be encrypted
UTF - 8 encoded string containing the plain text to be encrypted
associatedDataString
string
max. 16 character long string (not secret)
max . 16 character long string ( not secret )
nonce
byte[]
unique nonce; not secret but must never be used with the same private key before
unique nonce ; not secret but must never be used with the same private key before