Recently, in an android game, the client and Nodejs server data are encrypted using AES. It is found that Nodejs and java are encrypted in different forms. After querying the N-long data, I found that the java client needs to encrypt the key again by using MD5 (I wiped it out). This is a stranger to encryption...
The code for nodejs and JAVA is pasted below.
JAVA:
String DEFAULT_CODING = "utf-8" String decrypt(String encrypted, String seed) [] keyb = MessageDigest md = MessageDigest.getInstance("MD5" [] thedigest = SecretKeySpec skey = SecretKeySpec(thedigest, "AES" Cipher dcipher = Cipher.getInstance("AES" [] clearbyte = String encrypt(String content, String key) [] input = MessageDigest md = MessageDigest.getInstance("MD5" [] thedigest = SecretKeySpec skc = SecretKeySpec(thedigest, "AES" Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding" [] cipherText = ctLength = cipher.update(input, 0, input.length, cipherText, 0 ctLength += len = hexString.length() / 2 [] result = ( i = 0; i < len; i++ result[i] = Integer.valueOf(hexString.substring(2 * i, 2 * i + 2), 16 String parseByte2HexStr( StringBuffer sb = ( i = 0; i < buf.length; i++ String hex = Integer.toHexString(buf[i] & 0xFF (hex.length() == 1 hex = '0' + }
Node:
crypto = require('crypto'= cipher = crypto.createCipher('aes-128-ecb' cipher.update(data,'utf8','hex') + cipher.final('hex'= cipher = crypto.createDecipher('aes-128-ecb' cipher.update(data,'hex','utf8') + cipher.final('utf8'
Google suffered a headache for a day ~