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

Need Your Help

Can't change Navigation bar text font and color at the same time

ios swift uinavigationcontroller uinavigationbar

I’m trying to change the text font and color at the same time but unfortunately only one of them change. Please where would be my issue?

how to compare today date to given date

jsp

i want to compare to current date to given date in database just i want to test with this code but this is always showing false if current date equals to given date