Function eth_keystore::encrypt_key[][src]

pub fn encrypt_key<P, R, B, S>(
    dir: P,
    rng: &mut R,
    pk: B,
    password: S
) -> Result<String, KeystoreError> where
    P: AsRef<Path>,
    R: Rng + CryptoRng,
    B: AsRef<[u8]>,
    S: AsRef<[u8]>, 
Expand description

Encrypts the given private key using the Scrypt password-based key derivation function, and stores it in the provided directory.

Example

use eth_keystore::encrypt_key;
use rand::RngCore;
use std::path::Path;

let dir = Path::new("./keys");
let mut rng = rand::thread_rng();

// Construct a 32-byte random private key.
let mut private_key = vec![0u8; 32];
rng.fill_bytes(private_key.as_mut_slice());

let uuid = encrypt_key(&dir, &mut rng, &private_key, "password_to_keystore")?;