pub struct Cipher { /* fields omitted */ }
Create a new cipher object in the specified direction
let aes_gcm = botan::Cipher::new("AES-128/GCM", botan::CipherDirection::Encrypt).unwrap();
Return the name of this algorithm which may or may not exactly
match what was provided to new()
let cipher = botan::Cipher::new("AES-128/GCM", botan::CipherDirection::Encrypt).unwrap();
assert_eq!(cipher.algo_name().unwrap(), "AES-128/GCM(16)");
Return the direction this cipher object is operating in
let cipher = botan::Cipher::new("AES-128/GCM", botan::CipherDirection::Encrypt).unwrap();
assert_eq!(cipher.direction().unwrap(), botan::CipherDirection::Encrypt);
Query if a particular nonce size is valid for this cipher
let aes_cbc = botan::Cipher::new("AES-128/CBC", botan::CipherDirection::Encrypt).unwrap();
assert_eq!(aes_cbc.valid_nonce_length(16), Ok(true));
assert_eq!(aes_cbc.valid_nonce_length(1), Ok(false));
For an AEAD, return the tag length of the cipher
let aes_cbc = botan::Cipher::new("AES-128/CBC", botan::CipherDirection::Encrypt).unwrap();
assert_eq!(aes_cbc.tag_length(), 0);
let aes_gcm = botan::Cipher::new("AES-128/GCM", botan::CipherDirection::Encrypt).unwrap();
assert_eq!(aes_gcm.tag_length(), 16);
Return the default nonce length for the cipher. Some ciphers only
support a single nonce size. Others support variable sizes, but some
particular size (typically 96 bits) is handled particularly efficiently.
let aes_gcm = botan::Cipher::new("AES-128/GCM", botan::CipherDirection::Encrypt).unwrap();
assert_eq!(aes_gcm.default_nonce_length(), 12);
Return information about the key lengths supported by this object
Set the key for the cipher
let aes_gcm = botan::Cipher::new("AES-128/GCM", botan::CipherDirection::Encrypt).unwrap();
aes_gcm.set_key(&vec![0; 16]).unwrap();
Set the associated data for the cipher. This only works for AEAD modes.
The key must already be set to set the AD.
let aes_gcm = botan::Cipher::new("AES-128/GCM", botan::CipherDirection::Encrypt).unwrap();
aes_gcm.set_key(&vec![0; 16]).unwrap();
aes_gcm.set_associated_data(&[1,2,3]).unwrap();
Encrypt or decrypt a message with the provided nonce. The key must
already have been set.
let aes_gcm = botan::Cipher::new("AES-128/GCM", botan::CipherDirection::Encrypt).unwrap();
aes_gcm.set_key(&vec![0; 16]).unwrap();
let nonce = vec![0; aes_gcm.default_nonce_length()];
let msg = vec![0; 48];
let ctext = aes_gcm.process(&nonce, &msg);
Clear all state associated with the key
Formats the value using the given formatter. Read more
Executes the destructor for this type. Read more