3

Is it possible to perform cryptographic operations inside a smart contract? I'm specifically thinking about simple hashing (SHA-1/256/3) and symmetric encryption (AES). Obviously, handling key material for encryption is an issue that has to be addressed. But is it possible, in general, to do these operations?

2

There's a crypto.h inside of the contracts/eosiolib folder that has SHA/ripemd methods.

AES should be done off-chain though since the cleartext would be visible to anyone replaying the blockchain and viewing the action arguments.

|improve this answer|||||
4

Yes! It's very much possible! Look at the Dice contract example on the eosio github or in the repo folder eos/contracts/dice The function shown is a sha256 hashing method called sha256( )

Link to the actual dice.cpp file containing it's use on github: The Eosio example dice.cpp file

|improve this answer|||||
  • In the example dice contract, where does the sha256() function come from? It isn't defined in the contract. – John Haager May 9 '18 at 23:15
  • 1
    @nsjames Seems to have answered your question, crypto.h in contracts/eos from the github repository. You can also check out the API documentation at EOSIO crypto.h API Documentation – Joshua Shope May 10 '18 at 4:34
1

Yes, it is possible. Please see here: https://github.com/EOSIO/eos/blob/master/contracts/eosiolib/crypto.h

Developers can also compile their favourite C/C++ crypto library to do things EOSIO natively doesn't support.

|improve this answer|||||
  • the link doesn't exist – ekkis Apr 9 '19 at 23:47
1

The operations in contracts should be as short as possible. Because it’s directly pertain to the block producing time.

I recommend you to do cryptographic things outside of contract and pass the results as binary to the contract.

  • 1
    base64 is not a good format for contracts to operate on. Contracts should operate on binary. – bytemaster May 10 '18 at 4:52
0

For everyone searching for the actual link to the cryptoapi, here it is!

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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