byte-aes
byte-aes is a simple wrapper around the popular aes crate. The goal is to perform Encrypt and Decrypt operations using the Advanced Encryption Standard 256 bit Algorithm conveninent to use instead of use Low level functions of the aes crate
How to use
Try encrypt with String
use byte_aes::Aes256Cryptor;
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);
}
Try encrypt with raw bytes
use byte_aes::Aes256Cryptor;
fn main() {
let key = "c4ca4238a0b923820dcc509a6f75849b";
let cryptor = Aes256Cryptor::try_from(key).unwrap();
let buf: [u8; 4] = [1, 0, 0, 1];
let encrypt_buf = cryptor.encrypt(buf);
let clear_buf = cryptor.decrypt(encrypt_buf);
println!("{clear_buf:?}");
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);
let clear_buf = cryptor.decrypt(encrypt_buf);
println!("{clear_buf:?}");
let buf = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 200]; let clear_buf = cryptor.decrypt(buf);
println!("{clear_buf:?}");
}