I have java encryption function code as
public String encrypt(String Data, String keySet) throws Exception {
byte[] keyByte = keySet.getBytes();
Key key = generateKey(keyByte);
Cipher c = Cipher.getInstance("AES");
c.init(Cipher.ENCRYPT_MODE, key); //2
byte[] encVal = c.doFinal(Data.getBytes()); //1
byte[] encryptedByteValue = new Base64().encode(encVal); //3
String encryptedValue = new String(encryptedByteValue); //4
return encryptedValue;
}
private static Key generateKey(byte[] keyByte) throws Exception {
Key key = new SecretKeySpec(keyByte, "AES");
return key;
}
Now I am trying to implement the same in NodeJs using crypto module code is: -
//buf is string data that i want to encrypt
function makeEncrypt(buf, callback) {
var enckey = "encryptionkey";
var cipher = crypto.createCipher(algorithm, enckey)
var crypted = cipher.update(buf, 'utf8', 'base64')
crypted += cipher.final('base64');
console.log("encrypted data is : " + crypted.toString());
callback(null, crypted);
}
But the encrypted data returned by both functions is different what I am doing wrong? if anyone can help!! thanks in advance.