nodejs和java的aes-128-ecb加密结果不一样
发布于 1年前 作者 linminqin 1398 次浏览

nodejs代码如下:

encryptUtils.aesEncrypt = function(data, secretKey) { var cipher = crypto.createCipher(‘aes-128-ecb’,secretKey); return cipher.update(data,’utf8’,’hex’) + cipher.final(‘hex’); }

java代码:

public static String encryptAESBy128ECB(String content, String password) throws Exception { Cipher cipher = Cipher.getInstance(“AES/ECB/PKCS5Padding”); byte[] raw = password.getBytes(“utf-8”); SecretKeySpec skeySpec = new SecretKeySpec(raw, “AES”); cipher.init(Cipher.ENCRYPT_MODE, skeySpec); byte[] encrypted = cipher.doFinal(content.getBytes(“utf-8”)); return bytesToHexString(encrypted); } 经测试两个结果不一样,有谁遇到过吗,目前的业务需求是nodejs和android之间的加解密通讯,然后遇到了这个问题

回到顶部