Solution to node. js AES encryption inconsistency

Source: Internet
Author: User

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 ~

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.