I thinking of developing some kind of application in which I need to have some kind of public key cryptography done by the smart contract. The sender sends some data to the smart contract encrypyted by smart contract's public key, will the smart contract be able to decrypt it, using the smart contracts private key ? While the smart contract decrypts the data, will everyone be able to see the plain text since its replicated on all the nodes ?

Since the smart contract is replicated on all the nodes across the network, will every one be able to see all the contents of the smart contract ?

2 Answers 2


Since the smart contract is replicated on all the nodes across the network, will every one be able to see all the contents of the smart contract?

Short answer: yes.

If the contract does the decryption, it needs to store the private key. If the private key is stored in the contract, it is replicated to every node, and yes, as a result every node will do the decryption.

There is probably some cryptographically complex way to do what you want, but I'd guess it's one of those things that you want reviewed by lots of people who know crypto and blockchains, and if you get even a bit of it wrong, your data would be vulnerable.

Depending on your use case, you might have data sent (encrypted with the contract's public key) to the contract and stored, but only decrypted by a node/app you control that has the private key secured.


When using public key cryptography (asymmetric cryptography) you have to differentiate between signing and encrypting.

  • A signature is a proof of the data being signed by the owner of a certain public key. Clear text can also be signed while remaining clear (not encypted).

  • Encryption ensures that only who has access to the private key corresponding to a certain public key can decrypt the content

Both can be used together or not (encrypted, signed or encrypted and signed).

Please, be aware that:

  1. A public key can not be used to decrypt a message, that is why it is a public key, it can securely be distributed in order to receive encrypted messages encrypted for that key or to verify that some data was signed by the owner of the correspondent private key.
  2. A private key can not be used to encrypt, it can only be used to decrypt or to sign
  • I messed up with the terms, I have edited the question.
    – jgm
    Jun 15, 2016 at 12:36
  • @jgm, even if your question has changed, my answer is still valid: A public key can not be used to decrypt a message. Moreover, a private key cannot be used to encrypt data, only to decrypt it and/or sing it
    – atfornes
    Jun 15, 2016 at 12:49
  • 2
    @atfornes The differentiation is misleading. You use keys always to encrypt/decrypt. Signature is only a specific case where you encrypt only an hash of the file and not all the file content. There's nothing that distinguish private and public keys, but only the fact that you keep one secret and the other public. So, you can decrypt with a public key: it is in fact exactly what you need to do when you want to verify a sign, that is an hash encrypted with a private key. Jun 15, 2016 at 15:45
  • You are right @GiuseppeBertone, thanks for the comment. Please, feel free to propose an edit to my answer. I wrote the answer this way so private and public keys could easily be differentiated, since in the first versions of the question seemed not to be clear. Now the question is much clearer and JamieHale has a really god answer to it.
    – atfornes
    Jun 16, 2016 at 8:19
  • 1
    "There's nothing that distinguish private and public keys" - that's not really true, and also depends on the cryptosystem. You can derive the public key from the private key, but not vice-versa. Jan 10, 2017 at 11:11

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.