dbms_crypto and CryptoJS.HmacSHA256 returns different output

214 Views Asked by At

the javascript version and plsql code doesnt return the same output.

Javascript code:

var hash = CryptoJS.HmacSHA256(StringToSign,l_secret_key);
var hashutf8 = CryptoJS.enc.Utf8.parse(hash);
var hashInBase64 = CryptoJS.enc.Base64.stringify(hashutf8);

stringtosign =
POST 
d6acee532d731af58745efea44ba83a8
application/json 
unix_time 
/v2/user_auth_sign_in

l_secret_key = wBp1U6tFIw6Jzdy66v4mbRZB3P6Q6tjk

output : ZDJkY2Y1YWNlOWU0MDY4MWZmMGZhMzQ2MjU0MGIzZTE0ODNjYjdkMjlhNjkxZDg5ZDg1N2Q3M2JjZDdiMDk1NA==

But the similar code in PLSQL returns different output .

l_sig_mac :=
DBMS_CRYPTO.mac(UTL_I18N.string_to_raw(l_stringto_sign, 'AL32UTF8'), DBMS_CRYPTO.HMAC_SH256, UTL_I18N.string_to_raw(l_secret_key, 'AL32UTF8'));
l_base64_sig_mac := UTL_RAW.cast_to_varchar2(UTL_ENCODE.base64_encode(l_sig_mac));
DBMS_OUTPUT.put_line('MAC Signature (Base64-encoded): ' || l_base64_sig_mac);

output : K3BObVJEcUVmNVNhV3NZN1ovQ2dIVGtZWU9rcTF2T0xaVGxzdFdkQ3lBZz0=

What changes is expected in plsql block to receive same output as js?

Thank you

0

There are 0 best solutions below