twoSha256() public static method

Returns a double SHA256 hash of a value.
public static twoSha256 ( string $data, $binary = false ) : string
$data string
return string
示例#1
0
 /**
  * @see https://github.com/bitpay/bitcore/blob/master/test/test.util.js
  */
 public function testTwoSha256()
 {
     $data = array(array('907c2bc503ade11cc3b04eb2918b6f547b0630ab569273824748c87ea14b0696526c66ba740200000000fd1f9bdd4ef073c7afc4ae00da8a66f429c917a0081ad1e1dabce28d373eab81d8628de80200000000ad042b5f25efb33beec9f3364e8a9139e8439d9d7e26529c3c30b6c3fd89f8684cfd68ea0200000000599ac2fe02a526ed040000000008535300516352515164370e010000000003006300ab2ec2291fe51c6f', '60d8ec2b9241235914528efcc7b32315062d78c8dc12e09bbfdd4cb00563be5b'));
     foreach ($data as $datum) {
         $this->assertSame($datum[1], Util::twoSha256($datum[0]));
     }
 }
示例#2
0
 /**
  * Generates a Service Identification Number (SIN), see:
  * https://en.bitcoin.it/wiki/Identity_protocol_v1
  *
  * @return SinKey
  * @throws \Exception
  */
 public function generate()
 {
     if (is_null($this->publicKey)) {
         throw new \Exception('Public Key has not been set');
     }
     $compressedValue = $this->publicKey;
     if (empty($compressedValue)) {
         throw new \Exception('The Public Key needs to be generated.');
     }
     $step1 = Util::sha256(Util::binConv($compressedValue), true);
     $step2 = Util::ripe160($step1);
     $step3 = sprintf('%s%s%s', self::SIN_VERSION, self::SIN_TYPE, $step2);
     $step4 = Util::twoSha256(Util::binConv($step3), true);
     $step5 = substr(bin2hex($step4), 0, 8);
     $step6 = $step3 . $step5;
     $this->value = Base58::encode($step6);
     return $this;
 }