Cryptography global variables
Solidity provides cryptographic functions for hashing values within contract functions. There are two hashing functions—SHA2 and SHA3.
The sha3
function converts the input into a hash based on the sha3
algorithm while sha256
converts the input into a hash based on the sha2
algorithm. There is another function, keccak256
, which is an alias of the SHA3 algorithm. It is recommended to use the keccak256
or sha3
functions for hashing needs.
The following screenshot of the code segment illustrates this:
The result of executing this function is shown in the following screenshot. The result of both the keccak256
and sha3
functions is the same:
All three of these functions work on tightly packed arguments, meaning that multiple parameters can be concatenated together to find a hash, as shown in the following code snippet:
keccak256(97, 98, 99)