Ecrypting data on chain

Let’s say that one wanted to store a mapping of social security numbers (SSN) to some data on chain.

Lets imagine that the data related to the SSN is a simple yes/no, true false.

mapping(bytes32 => bool) ssnMapping

You also want it so that this data cannot be viewed/interpreted by anyone using a blockchain explorer or eth client.

I had thought that I could just use the private key of the contract deployer to encrypt the data, but of course that means that anyone can use the public key to just decrypt all the data they find on the chain.

Conversely if I use the public key to encrypt the data then sure, that means that the data is only decryptable by the private key holder - however it does potentially leave clues for potential snoopers:


  • smart contract wants to securely store mapping of SSN 1234 to a value of false on the blockchain

  • smart contract uses public key to encrypt 1234 and then store this in ssnMapping with value of false.

  • lets imagine smart contract becomes successful and well known

  • Now lets say a hacker is interested in data that this contract has for SSN 1234. Hacker uses the known public key (of the contract owner/deployer) to encrypt 1234 and simply uses this to interrogate the data on chain

what is the best practice here ?