Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem Generating Signature #6

Open
carpabg opened this issue Jan 25, 2020 · 0 comments
Open

Problem Generating Signature #6

carpabg opened this issue Jan 25, 2020 · 0 comments

Comments

@carpabg
Copy link

carpabg commented Jan 25, 2020

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');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant