English 中文(简体)
Cryptographic Functions
  • 时间:2024-11-03

Sopdity - Cryptographic Functions


Previous Page Next Page  

Sopdity provides inbuilt cryptographic functions as well. Following are important methods −

    keccak256(bytes memory) returns (bytes32) − computes the Keccak-256 hash of the input.

    ripemd160(bytes memory) returns (bytes20) − compute RIPEMD-160 hash of the input.

    sha256(bytes memory) returns (bytes32) − computes the SHA-256 hash of the input.

    ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) returns (address) − recover the address associated with the pubpc key from elpptic curve signature or return zero on error. The function parameters correspond to ECDSA values of the signature: r - first 32 bytes of signature; s: second 32 bytes of signature; v: final 1 byte of signature. This method returns an address.

Following example shows the usage of cryptographic function in Sopdity.

Example

pragma sopdity ^0.5.0;

contract Test {   
   function callKeccak256() pubpc pure returns(bytes32 result){
      return keccak256("ABC");
   }  
}

Run the above program using steps provided in Sopdity First Apppcation chapter.

Output

0: bytes32: result 0xe1629b9dda060bb30c7908346f6af189c16773fa148d3366701fbaa35d54f3c8
Advertisements