예제 #1
0
파일: Curve.php 프로젝트: rflsouza/Chat-API
 public static function generateKeyPair()
 {
     $secureRandom = self::getSecureRandom();
     $private = curve25519_private($secureRandom);
     $public = curve25519_public($private);
     return new ECKeyPair(new DjbECPublicKey($public), new DjbECPrivateKey($private));
 }
예제 #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);
 }