-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
Hi, I had some problems generating the signature, as it seems to be wrong.
I've compared the result of the Ds_Signature and Ds_MerchantParams with a PHP Redsys Api which was working correctly. Finally I found the problem is how the signature is generate, in particular in the 3Des encryption step.
In the PHP API the result of the encryption is cropped by a multiplier (I don't know why).
protected static function encrypt3DESOpenSSL($message, $key)
{
$l = ceil(strlen($message) / 8) * 8;
$message = $message.str_repeat("\0", $l - strlen($message));
return substr(openssl_encrypt($message, 'des-ede3-cbc', $key, OPENSSL_RAW_DATA, "\0\0\0\0\0\0\0\0"), 0, $l);
}
Changing the 3Des encyption method in the node api finanly I get redsys working.
encrypt3DES(str, key) {
const secretKey = Buffer.from(key, 'base64');
const iv = Buffer.alloc(8, 0);
const cipher = crypto.createCipheriv('des-ede3-cbc', secretKey, iv);
cipher.setAutoPadding(false);
const en_key = cipher.update(zeroPad(str, 8), 'utf8', 'binary') + cipher.final('binary');
const l = Math.ceil(str.length / 8) * 8;
//$message = $message.str_repeat("\0", $l - strlen($message));
return Buffer.from(en_key.substr(0, l), 'binary').toString('base64');
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels