#aes #encryption-decryption #aes-256 #256-bit #standard #low-level #advanced

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

5 releases

0.2.2 Mar 9, 2024
0.2.1 Mar 9, 2024
0.2.0 Dec 27, 2023
0.1.2 Dec 23, 2023

#1043 in Cryptography

Download history 70/week @ 2024-07-20 79/week @ 2024-07-27 33/week @ 2024-08-03 35/week @ 2024-08-10 90/week @ 2024-08-17 81/week @ 2024-08-24 99/week @ 2024-08-31 129/week @ 2024-09-07 46/week @ 2024-09-14 88/week @ 2024-09-21 103/week @ 2024-09-28 25/week @ 2024-10-05 46/week @ 2024-10-12 43/week @ 2024-10-19 27/week @ 2024-10-26 59/week @ 2024-11-02

177 downloads per month
Used in rufendec

MIT license

12KB
165 lines

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 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:?}");
}

Dependencies

~595KB
~14K SLoC