refactor(crypto): 重命名并替换加密模块SM4
This commit is contained in:
2
index.js
2
index.js
@@ -2,14 +2,12 @@ const Common = require('./src/utils/Common')
|
|||||||
const Storage = require('./src/utils/Storage')
|
const Storage = require('./src/utils/Storage')
|
||||||
const crypto = require('./src/utils/Crypto')
|
const crypto = require('./src/utils/Crypto')
|
||||||
const GlobalConfig = require('./src/utils/GlobalConfig')
|
const GlobalConfig = require('./src/utils/GlobalConfig')
|
||||||
const SM4 = require('./src/utils/SM4')
|
|
||||||
const HttpUtil = require('./src/https/HttpUtil')
|
const HttpUtil = require('./src/https/HttpUtil')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
HttpUtil,
|
HttpUtil,
|
||||||
Common,
|
Common,
|
||||||
Storage,
|
Storage,
|
||||||
SM4,
|
|
||||||
crypto,
|
crypto,
|
||||||
GlobalConfig,
|
GlobalConfig,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@tiesheng/npm-tool",
|
"name": "@tiesheng/npm-tool",
|
||||||
"version": "1.0.26-zjut",
|
"version": "1.0.27-zjut",
|
||||||
"description": "npm tool package",
|
"description": "npm tool package",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ async function req(url, options) {
|
|||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
let data = res.data;
|
let data = res.data;
|
||||||
if (res.encrypt) {
|
if (res.encrypt) {
|
||||||
data = crypto.decrypt(data);
|
data = crypto.d(data);
|
||||||
data = Common.parseJSON(data, data);
|
data = Common.parseJSON(data, data);
|
||||||
}
|
}
|
||||||
resolve({data, recordsTotal: res.recordsTotal})
|
resolve({data, recordsTotal: res.recordsTotal})
|
||||||
@@ -136,7 +136,7 @@ async function post(url, data = {}, options = {}) {
|
|||||||
|
|
||||||
let newData = {}
|
let newData = {}
|
||||||
if (Storage.getEncryptBody()) {
|
if (Storage.getEncryptBody()) {
|
||||||
newData.encryptData = crypto.encrypt(JSON.stringify(data));
|
newData.encryptData = crypto.e(JSON.stringify(data));
|
||||||
} else {
|
} else {
|
||||||
newData = {...data};
|
newData = {...data};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
const SM4 = require("./SM4");
|
const R = require("./R");
|
||||||
|
|
||||||
class Crypto {
|
class Crypto {
|
||||||
|
|
||||||
constructor() {
|
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],
|
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]
|
rounds: [0xC2, 0x65, 0xD8, 0xFB, 0x4A, 0xD3, 0x7B, 0x05, 0xCD, 0xF0, 0x6E, 0xE4, 0x5D, 0x6D, 0x43, 0x6D]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
encrypt(content) {
|
e(content) {
|
||||||
return this.sm4.encrypt(content);
|
return this.r.e(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
decrypt(base64) {
|
d(base64) {
|
||||||
return this.sm4.decrypt(base64);
|
return this.r.d(base64);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ class Crypt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SM4 {
|
class R {
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
const v = (() => {
|
const v = (() => {
|
||||||
const x = new Uint8Array(16);
|
const x = new Uint8Array(16);
|
||||||
@@ -178,7 +178,7 @@ class SM4 {
|
|||||||
return block
|
return block
|
||||||
}
|
}
|
||||||
|
|
||||||
encrypt(plaintext) {
|
e(plaintext) {
|
||||||
let plainByteArray = Crypt.stringToArrayBufferInUtf8(plaintext)
|
let plainByteArray = Crypt.stringToArrayBufferInUtf8(plaintext)
|
||||||
let padded = this.padding(plainByteArray)
|
let padded = this.padding(plainByteArray)
|
||||||
let blockTimes = padded.length / UINT8_BLOCK
|
let blockTimes = padded.length / UINT8_BLOCK
|
||||||
@@ -218,7 +218,7 @@ class SM4 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
decrypt(ciphertext) {
|
d(ciphertext) {
|
||||||
let cipherByteArray = new Uint8Array()
|
let cipherByteArray = new Uint8Array()
|
||||||
if (this.cipherType === 'base64') {
|
if (this.cipherType === 'base64') {
|
||||||
cipherByteArray = Crypt.base64ToArrayBuffer(ciphertext)
|
cipherByteArray = Crypt.base64ToArrayBuffer(ciphertext)
|
||||||
@@ -261,4 +261,4 @@ class SM4 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = SM4
|
module.exports = R
|
||||||
Reference in New Issue
Block a user