4

Is it possible to perform public key encryption flow for elliptic-curve cryptography? https://en.wikipedia.org/wiki/Public-key_cryptography

I need to implement the following scenario:

  1. Alice generates a message.
  2. Alice encrypts it with Bob's Stellar's public key.
  3. Alice sends a message to Bob (via an insecure channel).
  4. Bob gets the message.
  5. Bob can decrypt this message only with his Stellar's private key.

I can't find a proper method inside the tweetnacl lib (https://github.com/dchest/tweetnacl-js). Could somebody can direct me in the right direction?

  • 1
    I conducted a research on that topic about half a year ago. Haven't found anything, looks like it's impossible. – Orbit Lens Nov 13 '18 at 10:46
0

https://github.com/dchest/tweetnacl-js#public-key-authenticated-encryption-box

Use https://github.com/dchest/ed2curve-js to convert keys from ed25519 to curve25519

| improve this answer | |
  • But I should provide mySecretKey here, in order to create box, but I want to encrypt only with publicKey and decrypt with user's privateKey. – Evgeny Svirsky Nov 13 '18 at 12:55
  • btw, this method doesn't work even with their test code.. seems like lib has broken: const clientKeys = nacl.box.keyPair(); const serverKeys = nacl.box.keyPair(); const nonce = new Uint8Array(nacl.box.nonceLength); for (let i = 0; i < nonce.length; i++) nonce[i] = (32+i) & 0xff; const msg = tweetnaclUtil.decodeUTF8('message to encrypt'); const clientBox = nacl.box(msg, nonce, serverKeys.publicKey, clientKeys.secretKey); const clientMsg = nacl.box.open(clientBox, newNonce(), clientKeys.publicKey, serverKeys.secretKey); console.log(clientMsg); in the console - null – Evgeny Svirsky Nov 13 '18 at 13:26
  • I haven't tried the JS code, I was using Python at the time I needed this. Elliptic curves don't have the same capabilities as RSA, which works both for signing and encryption. Encryption in EC is basically Diffie-Hellman key exchange, followed by symmetric-key encryption, like AES. DH is why you need keys from both users. – Johan Stén Nov 14 '18 at 7:26
0

To my knowledge, ed25519 keys (which Stellar uses) can only be used for digital signatures, but not for encryption. Agreed with Johan that you would need to convert your key in order to do something like this.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.