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§