Skip to content

Instantly share code, notes, and snippets.

@jiangzhuo
Created June 20, 2017 09:47
Show Gist options
  • Save jiangzhuo/14b1d0df3868d1a07663004646149af4 to your computer and use it in GitHub Desktop.
Save jiangzhuo/14b1d0df3868d1a07663004646149af4 to your computer and use it in GitHub Desktop.
coolpay
var trans_data = '{"exorderno":"10004200000001100042","transid":"02113013118562300203","waresid":1,"appid":"20004600000001200046","feetype":0,"money":3000,"count":1,"result":0,"transtype":0,"transtime":"2013-01-31 18:57:27","cpprivate":"123456"}';
var key = 'MjhERTEwQkFBRDJBRTRERDhDM0FBNkZBMzNFQ0RFMTFCQTBCQzE3QU1UUTRPRFV6TkRjeU16UTVNRFUyTnpnek9ETXJNVE15T1RRME9EZzROVGsyTVRreU1ETXdNRE0zTnpjd01EazNNekV5T1RJek1qUXlNemN4';
var sign = '28adee792782d2f723e17ee1ef877e7 166bc3119507f43b06977786376c0434 633cabdb9ee80044bc8108d2e9b3c86e';
var md5 = require('md5');
// var base64_encode = require('base64').encode;
// var base64_decode = require('base64').decode;
var base64_encode = function (input) {
return new Buffer(input).toString('base64')
};
var base64_decode = function (input) {
return new Buffer(input, 'base64').toString('ascii')
};
var key1 = base64_decode(key);
var key2 = key1.substr(40, key1.length - 40);
var key3 = base64_decode(key2);
console.log('key1', key1);
console.log('key2', key2);
console.log('key3', key3);
var [private_key, mod_key] = key3.split('+');
console.log('private_key', private_key);
console.log('mod_key', mod_key);
var BigInteger = require('jsbn').BigInteger;
var arr = sign.split(' ');
var data = '';
var d = new BigInteger(private_key);
var n = new BigInteger(mod_key);
for (let v of arr) {
v = new BigInteger(v, 16);
v = v.modPow(d, n);
data += new Buffer(v.toByteArray(), 'ascii').toString()
}
console.log('sign_md5', data);
var msg_md5 = md5(trans_data);
console.log('msg_md5', msg_md5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment