Function orion::default::chacha20_encrypt [−][src]
pub fn chacha20_encrypt(
key: &[u8],
plaintext: &[u8]
) -> Result<Vec<u8>, UnknownCryptoError>
IETF ChaCha20 encryption.
About:
- The nonce is automatically generated
- Returns a vector where the first 12 bytes are the nonce and the rest is the ciphertext
- The initial counter is set to
0
Parameters:
plaintext
: The data to be encryptedkey
: The secret key used to encrypt theplaintext
Security:
This does not provide any data integrity. If you need data integrity, you should be using a
ChaCha20_Poly1305
construct instead. In most cases you would want data integrity.
See RFC for more information.
Exceptions:
An exception will be thrown if:
key
is not 32 bytesplaintext
is emptyplaintext
is longer than (2^32)-2
Example:
use orion::default; use orion::utilities::util; let mut key = [0u8; 32]; // Replace this with the key used for encryption util::gen_rand_key(&mut key).unwrap(); let encrypted_data = default::chacha20_encrypt(&key, "Secret message".as_bytes()).unwrap();