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);
}