Crate webcryptobox

Source
Expand description

Webcryptobox provides convenient wrappers around OpenSSL to use WebCrypto compatible cryptography.

It works nicely together with the JavaScript Webcryptobox and Bash Webcryptobox.

Webcryptobox helps with elliptic curve key generation, derivation, fingerprinting, import and export as well as AES encryption and decryption.

§Example:

// Alice creates a key and sends her public key pem to Bob
let alice = webcryptobox::generate_private_key().unwrap();
let alice_public_key = webcryptobox::get_public_key(&alice).unwrap();
let alice_public_key_pem = webcryptobox::export_public_key_pem(&alice_public_key).unwrap();

// Bob also creates a key and sends his public key pem to Alice
let bob = webcryptobox::generate_private_key().unwrap();
let bobs_public_key = webcryptobox::get_public_key(&bob).unwrap();
let bob_public_key_pem = webcryptobox::export_public_key_pem(&bobs_public_key).unwrap();

// Alice uses Bobs public key to derive a shared key
let bobs_key = webcryptobox::import_public_key_pem(&bob_public_key_pem).unwrap();
let alice_shared_key = webcryptobox::derive_key(alice, bobs_key).unwrap();

// She now encrypts a message and sends the encrypted message and the iv to Bob
let data = (b"a secret message").to_vec();
let encrypted_message = webcryptobox::encrypt(&alice_shared_key, &data).unwrap();

// Now Bob derives the same shared secret
let alice_key = webcryptobox::import_public_key_pem(&alice_public_key_pem).unwrap();
let bobs_shared_key = webcryptobox::derive_key(bob, alice_key).unwrap();

// and decrypts the message
let message = webcryptobox::decrypt(&bobs_shared_key, &encrypted_message);

Structs§

EcKey
Public and optional private key on the given curve.

Enums§

Private
A tag type indicating that a key has private components.
Public
A tag type indicating that a key only has public components.

Functions§

decrypt
Decrypts aes encrypted data
derive_and_decrypt
Derives AES key from given private and public key and decrypts message.
derive_and_encrypt
Derives AES key from given private and public key and encrypts message.
derive_key
Derives AES key material to be used with encrypt and decrypt from given private and public key.
derive_password
Derives password bits from given private and public key.
encrypt
Encrypts data with aes-266-cbc
export_encrypted_private_key_pem
Export a encrypted private EC key in PEM format.
export_encrypted_private_key_pem_to
Export a encrypted private EC key in PEM format with key pair
export_private_key_pem
Export a private EC key in PEM format.
export_public_key_pem
Export a public EC key in PEM format.
generate_key
Generate AES key material to be used with encrypt and decrypt.
generate_private_key
Generate an EC private key.
get_public_key
Given a private EC key, derives the public EC key.
import_encrypted_private_key_pem
Import an encrypted private key PEM.
import_encrypted_private_key_pem_from
Import an encrypted private key PEM from key pair.
import_private_key_pem
Import a private key PEM.
import_public_key_pem
Import a public key PEM.
sha1_fingerprint_from_private_key
Calculate a SHA-1 fingeprint from a private key.
sha1_fingerprint_from_public_key
Calculate a SHA-1 fingeprint of a public key.
sha256_fingerprint_from_private_key
Calculate a SHA-256 fingeprint from a private key.
sha256_fingerprint_from_public_key
Calculate a SHA-256 fingeprint of a public key.