|
@@ -1,5 +1,4 @@
|
|
|
// 参考 https://github.com/darknessomi/musicbox/wiki/
|
|
|
-'use strict'
|
|
|
const crypto = require('crypto')
|
|
|
const bigInt = require('big-integer')
|
|
|
const modulus = '00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7'
|
|
@@ -17,7 +16,7 @@ String.prototype.hexEncode = function() {
|
|
|
return result
|
|
|
}
|
|
|
|
|
|
-function createSecretKey(size) {
|
|
|
+const createSecretKey = (size) => {
|
|
|
const keys = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
|
|
let key = ""
|
|
|
for (let i = 0; i < size; i++) {
|
|
@@ -28,7 +27,7 @@ function createSecretKey(size) {
|
|
|
return key
|
|
|
}
|
|
|
|
|
|
-function aesEncrypt(text, secKey) {
|
|
|
+const aesEncrypt = (text, secKey) => {
|
|
|
const _text = text
|
|
|
const lv = new Buffer('0102030405060708', "binary")
|
|
|
const _secKey = new Buffer(secKey, "binary")
|
|
@@ -38,12 +37,12 @@ function aesEncrypt(text, secKey) {
|
|
|
return encrypted
|
|
|
}
|
|
|
|
|
|
-function zfill(str, size) {
|
|
|
+const zfill = (str, size) => {
|
|
|
while (str.length < size) str = "0" + str
|
|
|
return str
|
|
|
}
|
|
|
|
|
|
-function rsaEncrypt(text, pubKey, modulus) {
|
|
|
+const rsaEncrypt = (text, pubKey, modulus) => {
|
|
|
const _text = text.split('').reverse().join('')
|
|
|
const biText = bigInt(new Buffer(_text).toString('hex'), 16),
|
|
|
biEx = bigInt(pubKey, 16),
|
|
@@ -52,8 +51,8 @@ function rsaEncrypt(text, pubKey, modulus) {
|
|
|
return zfill(biRet.toString(16), 256)
|
|
|
}
|
|
|
|
|
|
-const Encrypt = (obj) => {
|
|
|
- const text = JSON.stringify(obj)
|
|
|
+const encrypt = (params) => {
|
|
|
+ const text = JSON.stringify(params)
|
|
|
const secKey = createSecretKey(16)
|
|
|
const encText = aesEncrypt(aesEncrypt(text, nonce), secKey)
|
|
|
const encSecKey = rsaEncrypt(secKey, pubKey, modulus)
|
|
@@ -63,4 +62,4 @@ const Encrypt = (obj) => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-module.exports = Encrypt
|
|
|
+module.exports = encrypt
|