# How do I encrypt text using phpseclib and RSA with only the modulus and exponent?

I tried the answer to this question, but it did not work:

$rsa = new \Crypt_RSA(); $rsa->loadKey( array( 'e' => new \Math_BigInteger($exponent), 'n' => new \Math_BigInteger($modulus) ) ); $cipher = $rsa->encrypt($text, CRYPT_RSA_PRIVATE_FORMAT_PKCS1);

My modulus is a 512-character hexadecimal number and my exponent is 10001. I've tried many different solutions, but I haven't found one that made this work. I'm receiving this error:

Notice: Uninitialized string offset: 0 in BigInteger.php on line 547

## Answers

As you are using strings representing hexadecimal numbers you should tell that to Math_BigInteger

$rsa = new Crypt_RSA(); $rsa->loadKey( array( 'e' => new Math_BigInteger($exponent, 16), 'n' => new Math_BigInteger($modulus, 16) ) );