/** * {@inheritdoc} */ public function encryptKey(JWKInterface $key, $cek, array $complete_headers, array &$additional_headers) { $this->checkKey($key); $pub = RSAKey::toPublic(new RSAKey($key)); if (self::ENCRYPTION_OAEP === $this->getEncryptionMode()) { $encrypted = JoseRSA::encrypt($pub, $cek, $this->getHashAlgorithm()); Assertion::string($encrypted, 'Unable to encrypt the data.'); return $encrypted; } else { $res = openssl_public_encrypt($cek, $encrypted, $pub->toPEM(), OPENSSL_PKCS1_PADDING | OPENSSL_RAW_DATA); Assertion::true($res, 'Unable to encrypt the data.'); return $encrypted; } }