[−][src]Struct libaes::Cipher
AES cipher struct
The user would create a cipher first by calling new_<key-length>()
(e.g. new_128()
), and then
call encrypt and/or decrypt methods as needed.
Implementations
impl Cipher
[src]
pub fn new_128(user_key: &[u8; 16]) -> Cipher
[src]
Create an AES 128-bit cipher with a given key.
Once created, a cipher can encrypt or decrypt any times of data using the same key.
user_key
must be at length of 128-bits, i.e. 16 bytes.
Examples
use libaes::Cipher; let my_key = b"This is the key!"; // 16 bytes let cipher = Cipher::new_128(my_key);
pub fn new_192(user_key: &[u8; 24]) -> Cipher
[src]
Create an AES 192-bit cipher with a given key.
Once created, a cipher can encrypt or decrypt any times of data using the same key.
user_key
must be at length of 192-bits, i.e. 24 bytes.
Examples
use libaes::Cipher; let my_key = b"This is the key! 192 bit"; // 24 bytes let cipher = Cipher::new_192(my_key);
pub fn new_256(user_key: &[u8; 32]) -> Cipher
[src]
Create an AES 256-bit cipher with a given key.
Once created, a cipher can encrypt or decrypt any times of data using the same key.
user_key
must be at length of 256-bits, i.e. 32 bytes.
Examples
use libaes::Cipher; let my_key = b"This is the key!This is the key!"; // 32 bytes let cipher = Cipher::new_256(my_key);
pub fn cbc_encrypt(&self, iv: &[u8], data: &[u8]) -> Vec<u8>
[src]
Encrypt in CBC mode.
The input data is not modified. The output is a new Vec. Padding is done automatically.
iv
is a 16-byte slice. Panics if iv
is less than 16 bytes.
This method works for all key sizes.
Examples
use libaes::Cipher; let my_key = b"This is the key!"; // key is 16 bytes let plaintext = b"A plaintext"; // less than 16 bytes, will be padded automatically let iv = b"This is 16 bytes"; let cipher = Cipher::new_128(my_key); let encrypted = cipher.cbc_encrypt(iv, plaintext);
pub fn cbc_decrypt(&self, iv: &[u8], data: &[u8]) -> Vec<u8>
[src]
Decrypt in CBC mode.
The input data is not modified. The output is a new Vec. Padding is handled automatically.
iv
is a 16-byte slice. Panics if iv
is less than 16 bytes.
This method works for all key sizes.
Examples
use libaes::Cipher; let my_key = b"This is the key!"; let iv = b"This is 16 bytes"; let plaintext = b"This is plain text for AES"; let ciphertext = b"\xfe\x2e\xa4\x03\xd2\x65\xa9\xe6\x78\xee\x16\x35\xf3\xa6\xe6\xf4\ \xa3\x16\xb6\xd4\x35\x6d\x2b\x6f\x49\xff\x9e\x3c\xe4\x66\x16\xb9"; let cipher = Cipher::new_128(my_key); let decrypted = cipher.cbc_decrypt(iv, ciphertext); assert_eq!(plaintext, &decrypted[..]);
Auto Trait Implementations
impl RefUnwindSafe for Cipher
impl Send for Cipher
impl Sync for Cipher
impl Unpin for Cipher
impl UnwindSafe for Cipher
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,