-
Notifications
You must be signed in to change notification settings - Fork 0
Overview
Tom Auger edited this page Jun 27, 2018
·
1 revision
XChaCha-DotNet contains implementations of the following algorithms:
Class | Algorithm | Description |
---|---|---|
XChaChaAeadCipher | XChaCha20-Poly1305 IETF AEAD | XChaCha AEAD cipher with 192-bit nonce and 192-bit key. Poly-1305 used to compute the authentication tag. Supports Additional Authenticated Data. Can safely encrypt messages up to 2^64 bytes. |
XChaChaStream | XChaCha20-Poly1305 | XChaCha20 stream cipher using Poly-1305 to compute the authentication tags. Automatically generates and rotates nonces. Supports using Additional Authenticated Data. Can safely encrypt messages up to any practical limit. |
XChaChaBufferedStream | XChaCha20-Poly1305 | XChaCha20 stream cipher using Poly-1305 to compute the authentication tags. Automatically generates and rotates nonces and buffers the input stream to encrypt data in fixed sized blocks. Can safely encrypt messages up to any practical limit. |
XChaChaSecretBoxCipher | XChaCha20-Poly1305 | An implementation of the secret_box API in the NaCl crypto library using XChaCha20 for the cipher and Poly-1305 to compute the authentication tag. |
Example encryption/decryption using the XChaChaAeadCipher:
using (var key = XChaChaKey.Generate())
{
var aeadCipher = new XChaChaAeadCipher();
var nonce = XChaChaNonce.Generate();
var message = Encoding.UTF8.GetBytes("Test Message");
var ciphertext = aeadCipher.Encrypt(message, key, nonce);
}
var keyBytes = Convert.FromBase64String("XPRT6QuYZDdytKM55WW+gnZklhaJBcDnOWi1kEI2we4=");
var nonceBytes = Convert.FromBase64String("2eQuiE8Fy70rwlCAi5T2oVEj5MrwxJaT");
var ciphertext = Convert.FromBase64String("w2jUPkWL0PfvnNFM7xq4o9gcVKrMTkd6SsYhLQ==");
using (var key = new XChaChaKey(keyBytes))
{
var aeadCipher = new XChaChaAeadCipher();
var nonce = new XChaChaNonce(nonceBytes);
var message = aeadCipher.Decrypt(ciphertext, key, nonce);
}