/**
* Decrypt with RSAES-OAEP + MGF1+SHA256
*
* @param string $plaintext
* @param PublicKey $rsaPublicKey
* @return string
* @throws InvalidCiphertextException
*/
protected static function rsaEncrypt($plaintext, PublicKey $rsaPublicKey)
{
static $rsa = null;
if (!$rsa) {
$rsa = new RSA();
$rsa->setEncryptionMode(RSA::ENCRYPTION_OAEP);
$rsa->setMGFHash('sha256');
}
$rsa->loadKey($rsaPublicKey->getKey());
return $rsa->encrypt($plaintext);
}