binConv() public static method

Converts hex value into octet (byte) string
public static binConv ( $hex ) : string
return string
 /**
  * @inheritdoc
  */
 public function load($id)
 {
     if (!is_file($id)) {
         throw new \Exception(sprintf('Could not find "%s"', $id));
     }
     if (!is_readable($id)) {
         throw new \Exception(sprintf('"%s" cannot be read, check permissions', $id));
     }
     $encoded = file_get_contents($id);
     $decoded = openssl_decrypt(\Bitpay\Util\Util::binConv($encoded), self::METHOD, $this->password, 1, self::IV);
     if (false === $decoded) {
         throw new \Exception('Could not decode key');
     }
     return unserialize($decoded);
 }
示例#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;
 }
示例#3
0
 public function testBinConv()
 {
     $data = array(array('7361746f736869', 'satoshi'), array('0x7361746f736869', 'satoshi'));
     foreach ($data as $datum) {
         $this->assertSame($datum[1], Util::binConv($datum[0]));
     }
 }