#encryption #decryption #error

tinycrypt

Small & simple encryption library with minimal dependencies

1 unstable release

0.1.0 Jun 26, 2024

#1772 in Cryptography

Unlicense

7KB
75 lines

tinycrypt

Small & simple rust encryption library

Tinycript aims to be a small dependency that gives you an encrypt function and a decrypt one. Simple as that. No bloat, no unnecesary dependencies (and featues), and no crazy API.

Uses Argon2 & Aes-gcm-siv for cryptography.


lib.rs:

Tinycrypt

A small & simple encryption library.

Exports two functions (encrypt & decrypt) along with an error type (CryptographyError) that implements std::error::Error.

Basic usage:

use tinycrypt::{Encrypt, Decrypt, CryptographyError};

let data = "Hello world!";
let secure_password = "password";

let encrypted_data: Vec<u8> = encrypt(data.as_bytes(), secure_password.as_bytes()).unwrap();

println!("Data encrypted!");

let decrypted_data: Vec<u8> = decrypt(&encrypted_data, password.as_bytes()).unwrap();

//Can also pattern match, to seperate invalid passwords from actual errors.
match decrypt(&encrypted_data, password.as_bytes()) {
    Ok(data) => (), //do something with data
    Err(password_error @ CryptographyError::IncorrectPassword) => (), //do something with incorrect password
    Err(error) => (), //do something with a different error
}

println!("{}", String::from_utf8(&decrypted_data).unwrap());

Dependencies

~2–2.8MB
~59K SLoC