0
我想从Java(Android)发送数据到Node.js应用程序,除了加密不工作和Node.js没有正确解密,我真的不知道我在做什么。加密和解密数据通过传输通过Java到Node.js
的Java:
// Encrypt
byte[] input = jo.toString().getBytes("UTF-8");
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] thedigest = md.digest(ENCRYPTION_KEY.getBytes("UTF-8"));
SecretKeySpec skc = new SecretKeySpec(thedigest, "AES/ECB/PKCS5Padding");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, skc);
byte[] cipherText = new byte[cipher.getOutputSize(input.length)];
int ctLength = cipher.update(input, 0, input.length, cipherText, 0);
ctLength += cipher.doFinal(cipherText, ctLength);
String query = Base64.encodeToString(cipherText, Base64.DEFAULT);
query
然后被发送到我们的服务器和jo
是JSONObject
及以上的节点,我做:
var decipher = crypto.createDecipher('aes-128-ecb', encryption_key);
console.log("System: " + new Buffer(fullBuffer, "base64").toString("binary"));
chunks = []
chunks.push(decipher.update(new Buffer(fullBuffer, "base64").toString("binary") , 'hex', 'utf-8'));
chunks.push(decipher.final('utf-8'));
var txt = chunks.join("");
console.log("System: " + txt);
js = JSON.parse(txt);
console.log("System: " + js);
而且fullBuffer
是收到正确传输的POST数据
那么,什么问题? – 2012-07-13 19:57:52
如何在Java中正确加密数据,然后使用AES在Node.js中对其进行解密 – 2012-07-13 19:59:03
我看到一个可接受的答案Joe,但实际解决了什么问题? – 2012-07-15 20:58:32