Struct byte_aes::cryptor::Aes256Cryptor
source · pub struct Aes256Cryptor { /* private fields */ }Implementations§
source§impl Aes256Cryptor
impl Aes256Cryptor
pub fn new(key: [u8; 32]) -> Self
pub fn key(&self) -> &[u8] ⓘ
sourcepub fn encrypt<T, U>(&self, plaintext: T) -> Vec<u8>
pub fn encrypt<T, U>(&self, plaintext: T) -> Vec<u8>
Examples found in repository?
examples/text.rs (line 10)
3 4 5 6 7 8 9 10 11 12 13 14 15 16
fn main() {
let my_32byte_key = "Thisi$MyKeyT0Encryp!thislastTime";
let cryptor = Aes256Cryptor::try_from(my_32byte_key).unwrap();
let original_text = "I am Omkaram Venkatesh and
this is my plain text and some random chars 223@#$^$%*%^(!#@%$~@#$[]]'///\\drewe. Lets see if this gets encrypted now)".to_string();
let encrypted_bytes: Vec<u8> = cryptor.encrypt(&original_text);
let decrypted_text: String =
String::from_utf8_lossy(&cryptor.decrypt(encrypted_bytes).unwrap_or_default()).to_string();
assert_eq!(original_text, decrypted_text);
}More examples
examples/byte.rs (line 7)
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
fn main() {
let key = "c4ca4238a0b923820dcc509a6f75849b";
let cryptor = Aes256Cryptor::try_from(key).unwrap();
let buf: [u8; 4] = [1, 0, 0, 1];
//let buf:[u8;16] = [1, 0, 0, 1, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 0];
let encrypt_buf = cryptor.encrypt(buf);
//println!("{encrypt_buf:?}");
let clear_buf = cryptor.decrypt(encrypt_buf);
println!("{clear_buf:?}"); // [1,1]
let buf: [u8; 17] = [
1, 0, 0, 1, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 0,
];
let encrypt_buf = cryptor.encrypt(buf);
//println!("{encrypt_buf:?}");
let clear_buf = cryptor.decrypt(encrypt_buf);
println!("{clear_buf:?}"); // [1,1]
let buf = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 200]; // invalid data for decrypting
let clear_buf = cryptor.decrypt(buf);
println!("{clear_buf:?}");
}sourcepub fn decrypt<T, U>(&self, ciphertext: T) -> Result<Vec<u8>>
pub fn decrypt<T, U>(&self, ciphertext: T) -> Result<Vec<u8>>
Examples found in repository?
examples/text.rs (line 13)
3 4 5 6 7 8 9 10 11 12 13 14 15 16
fn main() {
let my_32byte_key = "Thisi$MyKeyT0Encryp!thislastTime";
let cryptor = Aes256Cryptor::try_from(my_32byte_key).unwrap();
let original_text = "I am Omkaram Venkatesh and
this is my plain text and some random chars 223@#$^$%*%^(!#@%$~@#$[]]'///\\drewe. Lets see if this gets encrypted now)".to_string();
let encrypted_bytes: Vec<u8> = cryptor.encrypt(&original_text);
let decrypted_text: String =
String::from_utf8_lossy(&cryptor.decrypt(encrypted_bytes).unwrap_or_default()).to_string();
assert_eq!(original_text, decrypted_text);
}More examples
examples/byte.rs (line 10)
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
fn main() {
let key = "c4ca4238a0b923820dcc509a6f75849b";
let cryptor = Aes256Cryptor::try_from(key).unwrap();
let buf: [u8; 4] = [1, 0, 0, 1];
//let buf:[u8;16] = [1, 0, 0, 1, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 0];
let encrypt_buf = cryptor.encrypt(buf);
//println!("{encrypt_buf:?}");
let clear_buf = cryptor.decrypt(encrypt_buf);
println!("{clear_buf:?}"); // [1,1]
let buf: [u8; 17] = [
1, 0, 0, 1, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 0,
];
let encrypt_buf = cryptor.encrypt(buf);
//println!("{encrypt_buf:?}");
let clear_buf = cryptor.decrypt(encrypt_buf);
println!("{clear_buf:?}"); // [1,1]
let buf = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 200]; // invalid data for decrypting
let clear_buf = cryptor.decrypt(buf);
println!("{clear_buf:?}");
}Trait Implementations§
source§impl Clone for Aes256Cryptor
impl Clone for Aes256Cryptor
source§fn clone(&self) -> Aes256Cryptor
fn clone(&self) -> Aes256Cryptor
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Debug for Aes256Cryptor
impl Debug for Aes256Cryptor
source§impl TryFrom<&String> for Aes256Cryptor
impl TryFrom<&String> for Aes256Cryptor
source§impl TryFrom<&str> for Aes256Cryptor
impl TryFrom<&str> for Aes256Cryptor
Auto Trait Implementations§
impl RefUnwindSafe for Aes256Cryptor
impl Send for Aes256Cryptor
impl Sync for Aes256Cryptor
impl Unpin for Aes256Cryptor
impl UnwindSafe for Aes256Cryptor
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more