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
anddecrypt
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
anddecrypt
. - 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.