java加密方法等效于节点js crypto

我有java加密function代码

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; } 

现在我尝试使用加密模块代码在NodeJs中实现相同的function: –

 //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); } 

但是这两个函数返回的加密数据与我做错了不同? 如果有人可以帮助!! 提前致谢。