Function orion::default::chacha20_decrypt [−][src]
pub fn chacha20_decrypt(
key: &[u8],
ciphertext: &[u8]
) -> Result<Vec<u8>, UnknownCryptoError>
IETF ChaCha20 decryption.
About:
- The initial counter is set to
0
- The ciphertext passed must be of the same format as the one returned by
default::chacha20_encrypt()
Parameters:
ciphertext
: The data to be decrypted with the first 12 bytes being the noncekey
: The secret key used to decrypt theciphertext
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 bytesciphertext
is less than 13 bytesciphertext
is longer than (2^32)-14
Example:
use orion::default; use orion::utilities::util; let mut key = [0u8; 32]; // Replace this with the key used for decryption util::gen_rand_key(&mut key).unwrap(); // Sample encrypted data where the first 12 bytes are the nonce let ciphertext = "VRjKWpyfx9p6YynWFgAvCM/ithgwXaRptiljrQDXWEI".as_bytes(); let decrypted_data = default::chacha20_decrypt(&key, ciphertext).unwrap();