I have a encryption function in Java that I am trying to convert to Javascript and for some reason the hash generated in the end is not the same.
I am using crypto for javascript and Mac for Java.
Javascript:
const time = 0,0,0,0,0,8,21,60; const signKey = 20,54,50,82; const hash = crypto .createHmac('sha1', new Buffer(signKey, 'base64')) .update(new Buffer(time)) .digest('hex'); console.log(`hash ${hash}`); Java:
byte[] time = 0,0,0,0,0,8,21,60; byte[] signKey = 20,54,50,82; SecretKeySpec signKey = new SecretKeySpec(signKey, "HmacSHA1"); Mac mac; mac = Mac.getInstance("HmacSHA1"); mac.init(signKey); byte[] hash = mac.doFinal(time); Javascript - Output:
hash = 52,56,48
Java - Output: hash = [-47, 30, -1]
I think I am missing to convert something in Javascript, but as I am not familiar with cryptos, I am not sure.
Thank you !
const time = 0,0,0,0,0,3,58,60;throws a syntax error in here, are you using a framework that allows this? From what i know, this should beconst time = [0,0,0,0,0,3,58,60];