#encryption-decryption #aes-256 #package #npm #npm-package #aes256-ctr #node-aes256

simple-aes

A simple to use AES256-ctr encypter and decrypter based of the npm package(aes256)

2 stable releases

1.0.1 Jan 13, 2023

#1382 in Cryptography

28 downloads per month

MIT license

5KB
69 lines

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

Dependencies

~2.6–3.5MB
~78K SLoC