I am trying to encrypt a password to sent to through an API for authentication. From the API I can get the public key in this form:
{ "result": {
"keyId": "L5gslEaP921gEI34N5JRVRIEbbx78WJN",
"key": {
"n": "871db29fbb487b988f2d610d83a1e699c59473d73f6d38efa8d21645524b5fb549d5ffbc6d527b261ff2291cf3b3c81f25a4cb13c801d6f6eb3cae624d74724830f1cb45ec803d8836274f1ddea61ec25d5c44ad7ed0b8a56976291bd06abaa0beb9e1ecbbc59662d20f8ae71191e8cbe617acee2349a64aa20846d4d8910e53",
"e": "10001"
} } }
I need to encrypt a user password and send it back to the API. I am using PHP and this is what I have so far, but am not getting a proper hex encrypted password to send back:
$modulus = "871db29fbb487b988f2d610d83a1e699c59473d73f6d38efa8d21645524b5fb549d5ffbc6d527b261ff2291cf3b3c81f25a4cb13c801d6f6eb3cae624d74724830f1cb45ec803d8836274f1ddea61ec25d5c44ad7ed0b8a56976291bd06abaa0beb9e1ecbbc59662d20f8ae71191e8cbe617acee2349a64aa20846d4d8910e53";
$exponent = "10001";
$plaintext = "********";
include('Crypt/RSA.php');
$rsa = new Crypt_RSA();
$modulus = new Math_BigInteger(base64_decode($modulus), 256);
$exponent = new Math_BigInteger(base64_decode($exponent), 256);
$rsa->loadKey(array('n' => $modulus, 'e' => $exponent));
$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
$ciphertext = $rsa->encrypt($plaintext);
echo $ciphertext;
How do I properly encode the password given the modulus and exponent from the API?