Пример #1
0
 private function generateSignature($header, $payload, $algorithm, $secret)
 {
     if (!array_key_exists($algorithm, self::$supportedAlgorithm)) {
         throw new \Exception('unsupported algorithm');
     }
     if (preg_match('/^HS/', $algorithm)) {
         $signature = hash_hmac(self::$supportedAlgorithm[$algorithm], CBOREncoder::encode(array($header, $payload)), $secret, true);
     } elseif (preg_match('/^RS/', $algorithm)) {
         $signature = $this->encryptRsa(self::$supportedAlgorithm[$algorithm], CBOREncoder::encode(array($header, $payload)), $secret);
     } else {
         throw new \Exception('unsupported algorithm');
     }
     return $signature;
 }
Пример #2
0
<?php

include "src/CBOR/CBOREncoder.php";
include "src/CBOR/CBORExceptions.php";
include "src/CBOR/Types/CBORByteString.php";
//target for encode
$target = array(true, array("variable1" => 100000, "variable2" => "Hello, World!", "Hello!"), 0.234, 0, null, 590834290589032580);
//encoded string
$encoded_data = \CBOR\CBOREncoder::encode($target);
//debug info output
$byte_arr = unpack("C*", $encoded_data);
echo "Byte hex map = " . implode(" ", array_map(function ($byte) {
    return "0x" . strtoupper(dechex($byte));
}, $byte_arr)) . PHP_EOL;
echo "Byte dec map = " . implode(" ", $byte_arr) . PHP_EOL;
//decode
$decoded_variable = \CBOR\CBOREncoder::decode($encoded_data);
//output
var_dump($decoded_variable);
Пример #3
0
 /**
  * @param string $data
  * @param string $format
  * @param array  $context
  *
  * @return mixed
  */
 public function decode($data, $format, array $context = array())
 {
     return Encoder::decode($data);
 }