Crate ecies_25519

Crate ecies_25519 

Source
Expand description

Elliptic Curve Integrated Encryption Scheme using x25519 ``

§Example Usage

use rand::SeedableRng;
use rand_core::{OsRng, TryRngCore};
use ecies_25519::{EciesX25519, generate_keypair, parse_public_key, parse_private_key};
use rand_chacha::ChaCha8Rng;

 let mut os_rng = rand_core::OsRng::default();
 let mut seed_prod = [0u8; 32];
 os_rng.try_fill_bytes(&mut seed_prod);

let mut cha_rng = ChaCha8Rng::from_seed(seed_prod);

let recv_kp = generate_keypair(&mut cha_rng);
let recv_pub_key = parse_public_key(&recv_kp.public_der).unwrap();
let recv_priv_key = parse_private_key(&recv_kp.private_der).unwrap();

let message = "I 💖🔒";

let ecies_inst = EciesX25519::new();

// Encrypt the message with the public key
let encrypted_data = ecies_inst.encrypt(
   &recv_pub_key,
   message.as_bytes(),
   &mut cha_rng
).unwrap();

// Decrypt the message with the private key
let decrypted_data_bytes = ecies_inst.decrypt(
  &recv_priv_key,
  &encrypted_data
).unwrap();

println!("Decrypted data is {}", String::from_utf8(decrypted_data_bytes.clone()).unwrap());

Re-exports§

pub use rand;
pub use rand_core;

Structs§

EciesX25519
KeyPairDer
Holds an X25519 key pair encoded in standard DER formats.
PublicKey
A Diffie-Hellman public key
StaticSecret
A Diffie-Hellman secret key that can be used to compute multiple SharedSecrets.

Enums§

Error
KeyParsingError

Functions§

generate_keypair
Generate a keypair, ready for use in ECIES
parse_private_key
Parses an X25519 or Ed25519 private key, automatically detecting PEM or DER format.
parse_public_key
Parses an X25519 or Ed25519 public key, automatically detecting PEM or DER format.