ECIES encryption implementation for Node.js
npm install @icealtria/eciescrypto module.
crypto module
bash
pnpm install ecies
`
Usage
`typescript
import { ECIES } from '@icealtria/ecies';
const ecies = new ECIES();
// Generate key pair
const keyPair = ecies.generateKeyPair();
const privateKey = keyPair.getPrivateKey();
const publicKey = keyPair.getPublicKey();
// Encrypt message
const message = Buffer.from("Hello world! 🌏");
const encryptedData = ecies.encrypt(publicKey, message);
console.log(encryptedData.toString('base64'))
// BIexVy5zciKoxoo5w/8Caa/PJPuzWBiU9WrtY9f5x0PwyjXigfmklwqGwqUH7k7P5KlBOs5hCoMHc/vMOZtyyDG8yPx2djfPpgQ+5kpUdmtNCl+y82mCNoGAFpP7vrTcv14I8bqhbahXGGKNFPto0QnEqGOtMxm69JNm+N1BDkwMrhTFy9txXnL9fHyMYQ==
// Decrypt message
const decryptedMessage = ecies.decrypt(privateKey, encryptedData);
console.log(decryptedMessage.toString());
// Hello World! 🌍
`
Implementation Details
$3
Standard implementation with complete security features.
$3
simpECIES is a minimalist implementation optimized for smaller ciphertext size. Note: this trades some security features for size reduction.
API Reference
$3
- generateKeyPair(): Generates a new key pair
- encrypt(publicKey, message): Encrypts a message using recipient's public key
- decrypt(privateKey, encryptedData): Decrypts message using recipient's private key
$3
- generateKeyPair(): Generates a new key pair
- encrypt(publicKey, message): Encrypts a message using recipient's public key
- decrypt(privateKey, encryptedData)`: Decrypts message using recipient's private key