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§
- Public and optional private key on the given curve.
Enums§
- A tag type indicating that a key has private components.
- A tag type indicating that a key only has public components.
Functions§
- Decrypts aes encrypted data
- Derives AES key from given private and public key and decrypts message.
- Derives AES key from given private and public key and encrypts message.
- Derives AES key material to be used with
encrypt
anddecrypt
from given private and public key. - Derives password bits from given private and public key.
- Encrypts data with aes-266-cbc
- Export a encrypted private EC key in PEM format.
- Export a encrypted private EC key in PEM format with key pair
- Export a private EC key in PEM format.
- Export a public EC key in PEM format.
- Generate AES key material to be used with
encrypt
anddecrypt
. - Generate an EC private key.
- Given a private EC key, derives the public EC key.
- Import an encrypted private key PEM.
- Import an encrypted private key PEM from key pair.
- Import a private key PEM.
- Import a public key PEM.
- Calculate a SHA-1 fingeprint from a private key.
- Calculate a SHA-1 fingeprint of a public key.
- Calculate a SHA-256 fingeprint from a private key.
- Calculate a SHA-256 fingeprint of a public key.