simple-aes

Crates.iosimple-aes
lib.rssimple-aes
version1.0.1
sourcesrc
created_at2023-01-13 18:09:26.988234
updated_at2023-01-13 18:17:03.532088
descriptionA simple to use AES256-ctr encypter and decrypter based of the npm package(aes256)
homepagehttps://github.com/zedgell/simple-aes256
repositoryhttps://github.com/zedgell/simple-aes256
max_upload_size
id758089
size4,963
Zachary K Edgell (zedgell)

documentation

README

simple-aes


A simple AES256-ctr based off the node-aes256 package

Example


use simple_aes::{encrypt, decrypt};

fn main() {
    // Key can be any length since it will be SHA256 hashed
    let encrypt = encrypt("12345abcdef", "my-super-secret-key").unwrap();

    let decrypt = decrypt(encrypt, "my-super-secret-key").unwrap();

    assert_eq!(decrypt, "12345abcdef".to_string())
}

Flow


  • Encryption:
    • Data and key is passed in.
    • Random 16 byte iv is created
    • Key is SHA256 hashed
    • Data is encrypted using the iv and the hash
    • The iv and the encrypted data are concatenated, base64 encoded and returned as a string
  • Decryption
    • Key is SHA256 encrypted
    • Encrypted data and key is passed in.
    • Data is base64 decoded to a Vec<u8>.
    • First 16 elements in the Vec are grab for the iv.
    • Every element after the first 16 is passed into decryption along with key
    • The decrypted data is returned as a string
Commit count: 0

cargo fmt