MD5 encryption and 91 verification for node JS

Source: Internet
Author: User

For http get requests sent back from 91, verification must be performed on the server to ensure that the received parameter verification is consistent with the sign parameter sent from HTTP.

The MD5 encryption verification process of node on the server side is as follows:

Var crypto = require('crypto');
Var md5 = crypto.createHash('md5');
Md5.update('parameter combination result');
Var result = md5.digest('hex');
Console.log('result =====',result);

The main problem is that the Chinese encoding is inconsistent. If it is English, the encryption result is consistent with the sign. To solve this problem, you need to use the node buff module.

Var Buffer = require('buffer').Buffer
Var buf = new Buffer(1024);
Var len = buf.write('parameter combination result', 0);
Var result = buf.toString('binary', 0, len);//To use binary to make the result consistent with sign, you can also use uft8, ascii

After the above processing, the parameter encryption result can be consistent with the sign to achieve the purpose of verification.

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: 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.