diff --git a/index.js b/index.js index 70faea8..72c2de4 100644 --- a/index.js +++ b/index.js @@ -2,14 +2,12 @@ const Common = require('./src/utils/Common') const Storage = require('./src/utils/Storage') const crypto = require('./src/utils/Crypto') const GlobalConfig = require('./src/utils/GlobalConfig') -const SM4 = require('./src/utils/SM4') const HttpUtil = require('./src/https/HttpUtil') module.exports = { HttpUtil, Common, Storage, - SM4, crypto, GlobalConfig, } diff --git a/package.json b/package.json index c34fdc0..0910659 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tiesheng/npm-tool", - "version": "1.0.26-zjut", + "version": "1.0.27-zjut", "description": "npm tool package", "main": "index.js", "scripts": { diff --git a/src/https/HttpUtil.js b/src/https/HttpUtil.js index 9aa72e0..b2caa94 100644 --- a/src/https/HttpUtil.js +++ b/src/https/HttpUtil.js @@ -100,7 +100,7 @@ async function req(url, options) { if (res.code === 200) { let data = res.data; if (res.encrypt) { - data = crypto.decrypt(data); + data = crypto.d(data); data = Common.parseJSON(data, data); } resolve({data, recordsTotal: res.recordsTotal}) @@ -136,7 +136,7 @@ async function post(url, data = {}, options = {}) { let newData = {} if (Storage.getEncryptBody()) { - newData.encryptData = crypto.encrypt(JSON.stringify(data)); + newData.encryptData = crypto.e(JSON.stringify(data)); } else { newData = {...data}; } diff --git a/src/utils/Crypto.js b/src/utils/Crypto.js index e702715..9765496 100644 --- a/src/utils/Crypto.js +++ b/src/utils/Crypto.js @@ -1,20 +1,20 @@ -const SM4 = require("./SM4"); +const R = require("./R"); class Crypto { constructor() { - this.sm4 = new SM4({ + this.r = new R({ padding: [0xA5, 0x3C, 0x7F, 0x12, 0xB8, 0x4D, 0x91, 0xE3, 0x2A, 0x6B, 0xF0, 0x1E, 0x85, 0xC9, 0x34, 0x67], rounds: [0xC2, 0x65, 0xD8, 0xFB, 0x4A, 0xD3, 0x7B, 0x05, 0xCD, 0xF0, 0x6E, 0xE4, 0x5D, 0x6D, 0x43, 0x6D] }) } - encrypt(content) { - return this.sm4.encrypt(content); + e(content) { + return this.r.e(content); } - decrypt(base64) { - return this.sm4.decrypt(base64); + d(base64) { + return this.r.d(base64); } } diff --git a/src/utils/SM4.js b/src/utils/R.js similarity index 99% rename from src/utils/SM4.js rename to src/utils/R.js index 07799fa..a0b8166 100644 --- a/src/utils/SM4.js +++ b/src/utils/R.js @@ -58,7 +58,7 @@ class Crypt { } } -class SM4 { +class R { constructor(config) { const v = (() => { const x = new Uint8Array(16); @@ -178,7 +178,7 @@ class SM4 { return block } - encrypt(plaintext) { + e(plaintext) { let plainByteArray = Crypt.stringToArrayBufferInUtf8(plaintext) let padded = this.padding(plainByteArray) let blockTimes = padded.length / UINT8_BLOCK @@ -218,7 +218,7 @@ class SM4 { } } - decrypt(ciphertext) { + d(ciphertext) { let cipherByteArray = new Uint8Array() if (this.cipherType === 'base64') { cipherByteArray = Crypt.base64ToArrayBuffer(ciphertext) @@ -261,4 +261,4 @@ class SM4 { } } -module.exports = SM4 +module.exports = R