/** @return void */ public function setUp() { // Generate private & public key, using a self-signed certificate $keypair = KeyPair::generate(); $privatekey = $keypair->getPrivateKey(); $csr = new CSR(new Principal(['C' => 'DE', 'ST' => 'Baden-Württemberg', 'L' => 'Karlsruhe', 'O' => 'XP', 'OU' => 'XP Team', 'CN' => 'XP Unittest', 'EMAIL' => '*****@*****.**']), $keypair); $cert = $csr->sign($keypair); $publickey = $cert->getPublicKey(); $this->cert = $cert; $this->publickey = $publickey; $this->privatekey = $privatekey; }
/** * @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; }