In the past I did a juce::RSAKey implementation in PHP that used phpseclib 1.0.18 under the hood.

It’s fairly old code, use at your own risk.

```
class RSAKey
{
/**
* @return array [0] = public key, [1] = private key */
public static function createNewPair ($numBits, $description)
{
$rsa = new Crypt_RSA();
$rsa->setPrivateKeyFormat (CRYPT_RSA_PRIVATE_FORMAT_XML);
$rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_XML);
$output = $rsa->createKey ($numBits);
$privateString = $output['privatekey'];
$privateXml = simplexml_load_string ($privateString);
libxml_clear_errors(); // prevent accumulation (and excessive memory usage) if the messages are not used
$m = base64_decode ((string) $privateXml->Modulus);
$e = base64_decode ((string) $privateXml->Exponent);
$d = base64_decode ((string) $privateXml->D);
$publicKey = new RSAKey();
$publicKey->part1 = new Math_BigInteger ($e, 256);
$publicKey->part2 = new Math_BigInteger ($m, 256);
$privateKey = new RSAKey();
$privateKey->part1 = new Math_BigInteger ($d, 256);
$privateKey->part2 = $publicKey->part2;
return array ($publicKey, $privateKey);
}
/**
* Initialise this RSA key from the given string representation obtained by JUCE.
*/
public function loadFromJuceString ($string)
{
list ($key_part1, $key_part2) = explode (',', $string);
$this->part1 = new Math_BigInteger ($key_part1, 16);
$this->part2 = new Math_BigInteger ($key_part2, 16);
}
/**
* @return string
* */
public function toJuceString ()
{
return ($this->part1->toHex () . ',' . $this->part2->toHex ());
}
/**
* Applies this key to the given message
*
* @return the encrypted message
*/
public function applyToValue ($message)
{
$result = new Math_BigInteger ();
$value = new Math_BigInteger (strrev ($message), 256);
$zero = new Math_BigInteger ();
while (!$value->equals ($zero))
{
$result = $result->multiply ($this->part2);
list ($value, $remainder) = $value->divide ($this->part2);
$result = $result->add ($remainder->modPow ($this->part1, $this->part2));
}
return strrev ($result->toBytes ());
}
private $part1;
private $part2;
}
```