Crate scryptenc

source ·
Expand description

The scryptenc crate is an implementation of the scrypt encrypted data format.

The format is defined here.

Examples

Encrypt and decrypt

use scryptenc::{Decryptor, Encryptor};

let password = "password";
let data = b"Hello, world!";

// Encrypt `data` using `password`.
let params = scrypt::Params::new(10, 8, 1).unwrap();
let cipher = Encryptor::with_params(data, password, params);
let encrypted = cipher.encrypt_to_vec();
assert_ne!(encrypted, data);

// And decrypt it back.
let cipher = Decryptor::new(encrypted, password).unwrap();
let decrypted = cipher.decrypt_to_vec().unwrap();
assert_eq!(decrypted, data);

Extract the scrypt parameters in the encrypted data

use scryptenc::{Encryptor, Params};

let password = "password";
let data = b"Hello, world!";

// Encrypt `data` using `password`.
let params = scrypt::Params::new(10, 8, 1).unwrap();
let cipher = Encryptor::with_params(data, password, params);
let encrypted = cipher.encrypt_to_vec();

// And extract the scrypt parameters from it.
let params = Params::new(encrypted).unwrap();
assert_eq!(params.log_n(), 10);
assert_eq!(params.n(), 1024);
assert_eq!(params.r(), 8);
assert_eq!(params.p(), 1);

Re-exports

pub use hmac::digest;
pub use scrypt;

Structs

Decryptor for the scrypt encrypted data format.
Encryptor for the scrypt encrypted data format.
The scrypt parameters used for the encrypted data.

Enums

The error type for the scrypt encrypted data format.