Aes256Cryptor

Struct Aes256Cryptor 

Source
pub struct Aes256Cryptor { /* private fields */ }

Implementations§

Source§

impl Aes256Cryptor

Source

pub fn new(key: [u8; 32]) -> Self

Source

pub fn key(&self) -> &[u8]

Source

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
Hide additional 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}
Source

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
Hide additional 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

Source§

fn clone(&self) -> Aes256Cryptor

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Aes256Cryptor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl TryFrom<&String> for Aes256Cryptor

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: &String) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&str> for Aes256Cryptor

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<String> for Aes256Cryptor

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: String) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.