Example #1
0
 /**
  * @param KeyPair $keys
  * @return IAsymmetricJWK
  */
 public static function fromKeys(KeyPair $keys)
 {
     if (!$keys->getPrivate() instanceof RSAPrivateKey) {
         throw new \RuntimeException('Private key of invalid type!');
     }
     if (!$keys->getPublic() instanceof RSAPublicKey) {
         throw new \RuntimeException('Public key of invalid type!');
     }
     $jwk = new RSAJWK();
     $jwk->public_key = $keys->getPublic();
     $jwk->private_key = $keys->getPrivate();
     $jwk->set[RSAKeysParameters::Exponent] = Base64urlUInt::fromBigInt($jwk->public_key->getPublicExponent());
     $jwk->set[RSAKeysParameters::Modulus] = Base64urlUInt::fromBigInt($jwk->public_key->getModulus());
     $jwk->set[RSAKeysParameters::PrivateExponent] = Base64urlUInt::fromBigInt($jwk->private_key->getPrivateExponent());
     return $jwk;
 }