[][src]Module libreauth::key

Key generation module

Cryptographic security

Many random generators are available, but not all of them are cryptographically secure. That is a problem because if a secret key may be predictable, the security of your system crumbles into pieces. This key generation module is a wrapper upon rand::OsRng which, as its name stands, is a rust wrapper around the operating system's RNG. If the OS's entropy source is not available, it fails instead of falling back to a less secure source.

You may read more about cryptographic security in rand's documentation.

Examples

Generate a random key and display it in several forms.

let key = libreauth::key::KeyBuilder::new().generate();
println!("Key: Vec<u8>: {:?}", key.as_vec());
println!("Key: hex String: {}", key.as_hex());
println!("Key: base 32 String: {}", key.as_base32());
println!("Key: base 64 String: {}", key.as_base64());
assert!(key.as_vec() == key.as_vec());
assert!(key.as_hex() == key.as_hex());
assert!(key.as_base32() == key.as_base32());
assert!(key.as_base64() == key.as_base64());

Generate two random key and test if they are different.

let k1 = libreauth::key::KeyBuilder::new().generate().as_vec();
let k2 = libreauth::key::KeyBuilder::new().generate().as_vec();
assert!(k1 != k2);

Structs

KeyBuilder

Random key builder.

Functions

libreauth_keygen

[C binding] Generate a random key.