Is there a way of encrypting substrate storage using the root key pair? Or is there anyway of making on chain data private to everyone but the system.
thanks
Substrate and Polkadot Stack Exchange is a question and answer site for developers building blockchains with the Substrate SDK. It only takes a minute to sign up.
Sign up to join this communityAll the information on a blockchain is public and available to all the participants of the network.
You can encrypt the data you want to store offchain using your keypair and store it the storage, see an example of how to Encrypt & Decrypt Messages with the PolkadotJS library.
See I highlighted the offchain word. It is important you do not encrypt it using a smart contract or a extrinsic, because the input of the extrinsic will have the raw data and it will be public and visible to all. In other words encrypt data before it is added to a blockchain, and then decrypt it after it has been retrieved from the blockchain.
With that said, think twice if you want to store sensible data in the Blockchain. One of the properties of Blockchain is immutability, that means that even if stored in encrypted form, the critical data will remain in the blockchain forever. In addition to the risk of key compromise, the encrypted data may be subject to brute force decryption attacks in the future, or breakthroughs in technology like quantum computing might render current encryption technologies ineffective.