-
-
Notifications
You must be signed in to change notification settings - Fork 898
Closed
Description
Hi team , i try implement solution to encrypt value with hexPublickey but i have issue
{"error":"phpseclib error: Message representative out of range (Processed Key Info: Key Type: phpseclib3\\Crypt\\RSA\\PublicKey, Length: 2047 bits)"}
i use same code in Node and Java and working fine and i try do in php but i have this error
$hexPublicKey = "30820******";
$value = "123";
try {
$derPublicKey = hex2bin($hexPublicKey);
$publicKey = RSA::load($derPublicKey);
$publicKey = $publicKey
->withPadding(RSA::ENCRYPTION_OAEP)
->withHash('sha256')
->withMGFHash('sha256');
$encrypted = $publicKey->encrypt($value);
$hexEncrypted = bin2hex($encrypted);
echo "Valor cifrado (hex): " . strtoupper($hexEncrypted) . "\n";
} catch (\Exception $e) {
echo "Error: No se pudo cifrar los datos.\n";
echo "Mensaje: " . $e->getMessage() . "\n";
}
Metadata
Metadata
Assignees
Labels
No labels