No internet connection
  1. Home
  2. Questions

Is there a library for encryption/decryption in EOS?

By @OceanicSix
    2019-03-26 14:10:02.788Z

    Is there an encryption library on EOS that we can use? For example, how can I encrypt a single string "hello". And I have checked the API documentation https://eosio.github.io/eosio.cdt/1.4.0/group__cryptoapi.html but still don't really understand how it works

    Solved in post #2, click to view
    • 3 replies
    1. Phil Li @phil
        2019-03-26 15:45:20.373Z

        The crypto api is used to hash a string, which is a one-way map that is hard to reverse.

        Encryption/decryption also require a secret key for recovering input from the encrypted data. However, since everything on blockchain is open to the public including your smart contract's binary code, you cannot write the secret key in your contract code or allow users to fill it as an action parameter. So how do you want to use the encryption?

        ReplySolution
        1. O@OceanicSix
            2019-03-26 15:58:19.952Z

            Oh, I see. So can I understand it in this way: It is useless to perform encryption on blockchain as both the code and user's parameter are public. The way to perform encryption is to do it off-chain and upload ciphertext to blockchain, then another user decrypt the ciphertext off-chain.

            1. Phil Li @phil
                2019-03-26 16:19:39.008Z

                Yes exactly. For example, you can use a centralized server for encryption/decryption aside from the blockchain.