Crate tinycrypt

Source
Expand description

§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());

Enums§

CryptographyError
Error type for library, handles bincode encoding/decoding errors and key generation errors. Also provides a unique error for incorrect passwords.

Functions§

decrypt
Function for decrypting data. Takes encrypted data and password input as a slice (&[T]) of u8 (bytes) and returns a Result wrapping a vector of u8.
encrypt
Function for encrypting data. Takes any data and password input as a slice (&[T]) of u8 (bytes) and returns a Result wrapping a vector of u8.