paulmillr / noble-curves

Audited & minimal JS implementation of elliptic curve cryptography.
https://paulmillr.com/noble
MIT License
621 stars 56 forks source link

x25519 encrypt/decrypt? #121

Closed getify closed 4 months ago

getify commented 4 months ago

I saw in another issue that you intentionally don't implement montgomery curve operations. I believe/assume this means you intentionally don't have an encrypt() / decrypt() method pair on the x25519 API, correct?

Is there a way to do so, perhaps with the abstract API or utils, given having the x25519 keypair ready?

I'd like to do something like this:

let encBuffer = encrypt(msgBuffer, x25519pk, ivBuffer);
let msgBuffer_2 = decrypt(encBuffer, x25519sk, ivBuffer);

Thanks for any guidance.

paulmillr commented 4 months ago

If you are talking about encrypting-to-public-key aka hybrid encryption, this is out of scope for noble-curves, because it involves using ciphers (noble-ciphers). The encryption itself does not involve curves at all. And we only provide low-level primitives per-package.

Dajiaji built HPKE.js on top of noble, conforming to RFC 9180, which has x25519 based encryption: https://github.com/dajiaji/hpke-js/blob/main/x/dhkem-x25519/README.md