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)
3fn main() {
4 let my_32byte_key = "Thisi$MyKeyT0Encryp!thislastTime";
5
6 let cryptor = Aes256Cryptor::try_from(my_32byte_key).unwrap();
7 let original_text = "I am Omkaram Venkatesh and
8 this is my plain text and some random chars 223@#$^$%*%^(!#@%$~@#$[]]'///\\drewe. Lets see if this gets encrypted now)".to_string();
9
10 let encrypted_bytes: Vec<u8> = cryptor.encrypt(&original_text);
11
12 let decrypted_text: String =
13 String::from_utf8_lossy(&cryptor.decrypt(encrypted_bytes).unwrap_or_default()).to_string();
14
15 assert_eq!(original_text, decrypted_text);
16}More examples
examples/byte.rs (line 7)
2fn main() {
3 let key = "c4ca4238a0b923820dcc509a6f75849b";
4 let cryptor = Aes256Cryptor::try_from(key).unwrap();
5 let buf: [u8; 4] = [1, 0, 0, 1];
6 //let buf:[u8;16] = [1, 0, 0, 1, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 0];
7 let encrypt_buf = cryptor.encrypt(buf);
8 //println!("{encrypt_buf:?}");
9
10 let clear_buf = cryptor.decrypt(encrypt_buf);
11 println!("{clear_buf:?}"); // [1,1]
12
13 let buf: [u8; 17] = [
14 1, 0, 0, 1, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 0,
15 ];
16 let encrypt_buf = cryptor.encrypt(buf);
17 //println!("{encrypt_buf:?}");
18
19 let clear_buf = cryptor.decrypt(encrypt_buf);
20 println!("{clear_buf:?}"); // [1,1]
21
22 let buf = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 200]; // invalid data for decrypting
23 let clear_buf = cryptor.decrypt(buf);
24 println!("{clear_buf:?}");
25}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)
3fn main() {
4 let my_32byte_key = "Thisi$MyKeyT0Encryp!thislastTime";
5
6 let cryptor = Aes256Cryptor::try_from(my_32byte_key).unwrap();
7 let original_text = "I am Omkaram Venkatesh and
8 this is my plain text and some random chars 223@#$^$%*%^(!#@%$~@#$[]]'///\\drewe. Lets see if this gets encrypted now)".to_string();
9
10 let encrypted_bytes: Vec<u8> = cryptor.encrypt(&original_text);
11
12 let decrypted_text: String =
13 String::from_utf8_lossy(&cryptor.decrypt(encrypted_bytes).unwrap_or_default()).to_string();
14
15 assert_eq!(original_text, decrypted_text);
16}More examples
examples/byte.rs (line 10)
2fn main() {
3 let key = "c4ca4238a0b923820dcc509a6f75849b";
4 let cryptor = Aes256Cryptor::try_from(key).unwrap();
5 let buf: [u8; 4] = [1, 0, 0, 1];
6 //let buf:[u8;16] = [1, 0, 0, 1, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 0];
7 let encrypt_buf = cryptor.encrypt(buf);
8 //println!("{encrypt_buf:?}");
9
10 let clear_buf = cryptor.decrypt(encrypt_buf);
11 println!("{clear_buf:?}"); // [1,1]
12
13 let buf: [u8; 17] = [
14 1, 0, 0, 1, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 0,
15 ];
16 let encrypt_buf = cryptor.encrypt(buf);
17 //println!("{encrypt_buf:?}");
18
19 let clear_buf = cryptor.decrypt(encrypt_buf);
20 println!("{clear_buf:?}"); // [1,1]
21
22 let buf = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 200]; // invalid data for decrypting
23 let clear_buf = cryptor.decrypt(buf);
24 println!("{clear_buf:?}");
25}Trait Implementations§
Source§impl Clone for Aes256Cryptor
impl Clone for Aes256Cryptor
Source§fn clone(&self) -> Aes256Cryptor
fn clone(&self) -> Aes256Cryptor
Returns a duplicate 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 Freeze for Aes256Cryptor
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