encrypt() public static method

Encryption.
public static encrypt ( RSAKey $key, string $plaintext, string $hash_algorithm ) : string
$key Jose\KeyConverter\RSAKey
$plaintext string
$hash_algorithm string
return string
示例#1
0
文件: RSA.php 项目: spomky-labs/jose
 /**
  * {@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;
     }
 }