mardi 29 septembre 2015

generating signature using base64_encode and hash_hmac in ruby on rails

I am con verting PHP code to Rails code and i am facing issues generating signature using base64_encode and hash_mac. The signature generated in php is 48 in length and while in Rails its varying in length.

How can i convert the below code to Rails

PHP Code:

return base64_encode(
    hash_hmac($hash, $data, $key, true)
);

Below is the Rails code i am using, but the singatures generated are of different length

Rails Code:

signature_val = Base64.encode64(OpenSSL::HMAC.digest('sha256', key, data))

Can anyone help me to convert the PHP code to Correct Rails code, so that i can generate the signature properly.

Thanks.

Aucun commentaire:

Enregistrer un commentaire