4

How can I do asymmetric encryption by using Stellar's private key of sender and Stellar's public key of receiver and vice-versa in case of case decryption? I had gone through many methods but I am not getting what I want.

  • 3
    There aren't that many options. tweetnacl-box, like, I showed you, does work. Maybe you can expand on what you're trying to accomplish? – Johan Stén Sep 27 '18 at 11:45
  • Yeah I tried using that but it is not accepting stellar's keypair. – pri Sep 27 '18 at 11:58
  • 1
    Of course it doesn't. ed25519 keys are signing keys. They need to be converted to curve25519 keys first. And before that, you need to convert the keys from StrKey encoding to raw binary. – Johan Stén Sep 27 '18 at 12:06
  • Yeah I know that but still I am facing problem because the library you suggested was written in js and I am a python developer – pri Sep 29 '18 at 5:28
  • There are python libraries for this also, that's what I used. Years ago though, so I don't remember what they are. – Johan Stén Oct 1 '18 at 5:08
0

Giving full credit to Johan here and mostly just want to have an answer down on this question.

In general, you need to take your Stellar keypair in its raw form (not its StrKey representation), convert it to a curve25519 key (which is definitely doable with libsodium and its various bindings in multiple languages, and take a look at the sealed box encryption provided in libsodium and friends.

In Python, you can use PyNaCl to utilize libsodium in Python. Summarizing the exact three steps he mentioned:

  1. Take your Stellar keypair and convert it from its StrKey encoding (traditionally GASOMELONGSETOFCHARACTERS for a public key) to the raw bytes. It's possible to do this using the Python SDK (take a look at the KeyPair class, and getting the raw bytes).
  2. Because it's an ed25519 key, you can't encrypt with it. You need to create a key based off of it (in particular, the easiest is to make a curve25519 key). You can do with nacl.signing.SigningKey.to_curve25519_private_key once you've instantiated the nacl.signing.SigningKey properly from your bytes (See the SigningKey class. You can see this public method in the docs.
  3. From there, encrypt using SealedBox in PyNaCl as you see fit.

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.