Exemplo n.º 1
0
 public static function generateKeyPair()
 {
     $secureRandom = self::getSecureRandom();
     $private = curve25519_private($secureRandom);
     $public = curve25519_public($private);
     return new ECKeyPair(new DjbECPublicKey($public), new DjbECPrivateKey($private));
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public static function createOKPKey(array $values)
 {
     Assertion::keyExists($values, 'crv', 'The curve is not set.');
     $curve = $values['crv'];
     switch ($curve) {
         case 'X25519':
             Assertion::true(function_exists('curve25519_public'), sprintf('Unsupported "%s" curve', $curve));
             $d = random_bytes(32);
             $x = curve25519_public($d);
             break;
         case 'Ed25519':
             Assertion::true(function_exists('ed25519_publickey'), sprintf('Unsupported "%s" curve', $curve));
             $d = random_bytes(32);
             $x = ed25519_publickey($d);
             break;
         default:
             throw new \InvalidArgumentException(sprintf('Unsupported "%s" curve', $curve));
     }
     $values = array_merge($values, ['kty' => 'OKP', 'crv' => $curve, 'x' => Base64Url::encode($x), 'd' => Base64Url::encode($d)]);
     return new JWK($values);
 }