#elliptic-curve #encryption-key #ecies #x25519 #public-key #scheme #integrated

ecies_25519

Elliptic Curve Integrated Encryption Scheme with X25519 curve

5 releases

0.1.4 Feb 7, 2025
0.1.3 Feb 7, 2025
0.1.2 Feb 16, 2024
0.1.1 Jan 9, 2024
0.1.0 Nov 25, 2021

#1446 in Cryptography

Download history 2/week @ 2024-10-30 2/week @ 2024-11-06 4/week @ 2024-12-04 7/week @ 2024-12-11 247/week @ 2025-02-05

247 downloads per month
Used in c5store

MPL-2.0 and LGPL-3.0-only

11KB
179 lines

Elliptic Curve Integrated Encryption Scheme using x25519 ``

Example Usage

use rand::SeedableRng;
use rand_core::{OsRng, TryRngCore};
use ecies_25519::{EciesX25519, generate_keypair, parse_openssl_25519_pubkey_der, parse_openssl_25519_privkey_der};
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).unwrap();
let recv_pub_key = parse_openssl_25519_pubkey_der(&recv_kp.public_der).unwrap();
let recv_priv_key = parse_openssl_25519_privkey_der(&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());

Dependencies

~7.5MB
~133K SLoC