Skip to content

Encrypt sha255 error 2047 Bits #2085

@adrianlaraperez88

Description

@adrianlaraperez88

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions