You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public byte[] encrypt(byte[] data, byte[] key) throws Exception {
SecretKeySpec keySpec = new SecretKeySpec(key, "AES");
byte[] iv = new byte[16];
IvParameterSpec ivSpec = new IvParameterSpec(iv);
Cipher acipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
byte[] arrayOfByte1;
acipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec);
arrayOfByte1 = acipher.doFinal(data);
return arrayOfByte1;
}
This is the javascript code for the same functionality. I am using the crypto-js library.
var crypto = require('crypto-js');
populateHMAC( app_id, mobile, token, deviceId){
var rawStr = token;
var wordArray = crypto.enc.Utf8.parse(rawStr);
var base64 = crypto.enc.Base64.stringify(wordArray);
var enctoken=btoa(token);
var message= app_id + "|" + mobile + "|" + deviceId;
var decodedString= atob(enctoken);
message=encodeURIComponent(message);
var hash= crypto.SHA256(message);//.toString(crypto.enc.Utf8);
console.log("params",decodedString,hash.toString(crypto.enc.Hex));
var iv = crypto.enc.Hex.parse('0000000000000000');
var encryptedString = crypto.AES.encrypt(hash, decodedString, {
iv:iv,
mode: crypto.mode.CBC,
padding: crypto.pad.Pkcs7
});
var encodedString= encryptedString.ciphertext.toString(crypto.enc.Base64);
return encodedString;
}
The two outputs are different and I am unable to figure out why.
The text was updated successfully, but these errors were encountered:
This is the java code. I am trying to replicate the same functionality in javascript.
public String populateHMAC(String app_id, String mobile, String token,
String deviceId) {
}
These are the functions inside CryptLib
The SHA256 function
}
And the encrypt function
}
This is the javascript code for the same functionality. I am using the crypto-js library.
The two outputs are different and I am unable to figure out why.
The text was updated successfully, but these errors were encountered: