Diffie-Hellman encryption
@webbuf/acb3p256dh
AES+CBC encryption/decryption with blake3 mac and P-256 (NIST) Diffie-Hellman shared secret
Install
npm install @webbuf/acb3p256dh Usage
import { acb3p256dhEncrypt, acb3p256dhDecrypt } from "@webbuf/acb3p256dh";
import { p256PublicKeyCreate } from "@webbuf/p256";
import { WebBuf } from "@webbuf/webbuf";
import { FixedBuf } from "@webbuf/fixedbuf";
// Alice and Bob generate key pairs
const alicePrivKey = FixedBuf.fromRandom<32>(32);
const alicePubKey = p256PublicKeyCreate(alicePrivKey);
const bobPrivKey = FixedBuf.fromRandom<32>(32);
const bobPubKey = p256PublicKeyCreate(bobPrivKey);
// Alice encrypts a message to Bob
const plaintext = WebBuf.fromUtf8("Hello Bob!");
const ciphertext = acb3p256dhEncrypt(alicePrivKey, bobPubKey, plaintext);
// Bob decrypts the message from Alice
const decrypted = acb3p256dhDecrypt(bobPrivKey, alicePubKey, ciphertext);
console.log(decrypted.toUtf8()); // "Hello Bob!" API reference (2 exports)
Functions
acb3p256dhDecrypt
functionUse Alice's private key and Bob's public key to derive a shared secret (Diffie-Hellman with P-256) and use that shared secret as the decryption key for ACB3 decryption.
acb3p256dhDecrypt(alicePrivKey: FixedBuf<32>, bobPubKey: FixedBuf<33>, ciphertext: WebBuf): WebBuf acb3p256dhEncrypt
functionUse Alice's private key and Bob's public key to derive a shared secret (Diffie-Hellman with P-256) and use that shared secret as the encryption key for ACB3 encryption.
acb3p256dhEncrypt(alicePrivKey: FixedBuf<32>, bobPubKey: FixedBuf<33>, plaintext: WebBuf, iv?: FixedBuf<16>): WebBuf