This repo demonstrates ECIES encryption using secp256k1 + AES-GCM, with fully working Rust β JavaScript/TypeScript interoperability.
- EC key exchange via
secp256k1(ECDH) - AES-256-GCM for authenticated encryption
- HKDF for key derivation
rust/β Full keygen + ECIES encrypt/decrypt in Rust (withclap-based CLI)js/β TypeScript ECIES using@noble/secp256k1+ WebCrypto +commanderCLI
git clone https://github.com/Cardinal-Cryptography/ecies-encryption-poc.git
cd ecies-encryption-pocRun the rust example
cd rust
cargo build
./target/debug/ecies-rust-poc exampleOr run subcommands like:
./target/debug/ecies-rust-poc generate-keypair
./target/debug/ecies-rust-poc encrypt --pubkey <hex> --message "hello"
./target/debug/ecies-rust-poc decrypt --privkey <hex> --ciphertext <hex>Run the TypeScript example
cd js
npm installThen
npx ts-node index.ts example
npx ts-node index.ts generate-keypair
npx ts-node index.ts encrypt --pubkey <hex> --message "hello"
npx ts-node index.ts decrypt --privkey <hex> --ciphertext <hex>We include an integration test for JS <--> Rust compatibility.
./ecies-integration-test.sh
Using encrypt or decrypt directly does not hide plaintext length which might be a problem in some cases. One needs do further work in order to fix that (add padding carefully).