4

If data is encrypted using the public key from a wallet is there a way to decrypt that data using the private key of the wallet? I am essentially looking for the inverse of signData from CIP-0030. I'd like to encrypt a payload using the public key and then allow the user to decrypt it with their private key.

5
  • 1
    Please have a look at crypto.stackexchange.com/questions/83266/…
    – Fermat
    Commented Jun 10, 2022 at 8:42
  • @Fermat thank you for the link as it was very helpful. What I had in mind was en.wikipedia.org/wiki/ElGamal_encryption where the key generation had already occurred when the wallet was created. From the answer in the link you posted, it looks like that should work fine or am I misreading that? Commented Jun 10, 2022 at 16:06
  • 1
    I am familiar with El-Gamal (look at github.com/fermatspace/el-gamal-onchain for a small experiment onchain). The problem with key generation in the wallet is that it uses Ed25519 keys (El-gamal uses big integers). Now of course you could convert the Ed25519 binary representation of a key to an integer to fix this, but you will have to build the tools.
    – Fermat
    Commented Jun 10, 2022 at 16:12
  • @Fermat thank you again. It is very cool that you already put together a little proof-of-concept for El-Gamal encryption on chain. Converting the binary representation of the Ed25519 key to an integer makes sense and I have no problem building the tools to do all this. Thank you for your help! Commented Jun 10, 2022 at 16:23
  • No problem! Looking forward to your implementation :) Hope you open source it!
    – Fermat
    Commented Jun 10, 2022 at 16:54

1 Answer 1

2

There is a difference in encryption and signing.

  • Signing is the act of providing a piece of evidence alongside data that prove that the information is processed with a particular signing key. Given a public corresponding to the singing private key you can check if the data is aproved by that public key.

  • Encryption is the act of obscuring data to make it not readable. Depending on what type of encryption you use, symmetric vs asymmetric, one can encrypt the data with a private key or public key. Decrypting can only be done with the private key.

Cardano's wallets use an elliptic curve signature scheme (1). Note that this can not encrypt data! It can only create signatures, you can verify signatures onchain with, for example (2). If you want to encrypt some data, you have to use another scheme (like the mentioned El-Gamal encryption scheme).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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