|
@@ -1,161 +1,8 @@
|
|
|
-import base64js from "./base64.js"
|
|
|
-(function(r) {
|
|
|
- if (typeof exports === "object" && typeof module !== "undefined") {
|
|
|
- module.exports = r()
|
|
|
- } else {
|
|
|
- if (typeof define === "function" && define.amd) {
|
|
|
- define([], r)
|
|
|
- } else {
|
|
|
- var e;
|
|
|
- if (typeof window !== "undefined") {
|
|
|
- e = window
|
|
|
- } else {
|
|
|
- if (typeof global !== "undefined") {
|
|
|
- e = global
|
|
|
- } else {
|
|
|
- if (typeof self !== "undefined") {
|
|
|
- e = self
|
|
|
- } else {
|
|
|
- e = this
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- e.base64js = r()
|
|
|
- }
|
|
|
- }
|
|
|
-})(function() {
|
|
|
- var r, e, t;
|
|
|
- return function r(e, t, n) {
|
|
|
- function o(i, a) {
|
|
|
- if (!t[i]) {
|
|
|
- if (!e[i]) {
|
|
|
- var u = typeof require == "function" && require;
|
|
|
- if (!a && u) {
|
|
|
- return u(i, !0)
|
|
|
- }
|
|
|
- if (f) {
|
|
|
- return f(i, !0)
|
|
|
- }
|
|
|
- var d = new Error("Cannot find module '" + i + "'");
|
|
|
- throw d.code = "MODULE_NOT_FOUND", d
|
|
|
- }
|
|
|
- var c = t[i] = {
|
|
|
- exports: {}
|
|
|
- };
|
|
|
- e[i][0].call(c.exports, function(r) {
|
|
|
- var t = e[i][1][r];
|
|
|
- return o(t ? t : r)
|
|
|
- }, c, c.exports, r, e, t, n)
|
|
|
- }
|
|
|
- return t[i].exports
|
|
|
- }
|
|
|
- var f = typeof require == "function" && require;
|
|
|
- for (var i = 0; i < n.length; i++) {
|
|
|
- o(n[i])
|
|
|
- }
|
|
|
- return o
|
|
|
- }({
|
|
|
- "/": [function(r, e, t) {
|
|
|
- t.byteLength = c;
|
|
|
- t.toByteArray = v;
|
|
|
- t.fromByteArray = s;
|
|
|
- var n = [];
|
|
|
- var o = [];
|
|
|
- var f = typeof Uint8Array !== "undefined" ? Uint8Array : Array;
|
|
|
- var i = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
|
- for (var a = 0, u = i.length; a < u; ++a) {
|
|
|
- n[a] = i[a];
|
|
|
- o[i.charCodeAt(a)] = a
|
|
|
- }
|
|
|
- o["-".charCodeAt(0)] = 62;
|
|
|
- o["_".charCodeAt(0)] = 63;
|
|
|
-
|
|
|
- function d(r) {
|
|
|
- var e = r.length;
|
|
|
- if (e % 4 > 0) {
|
|
|
- throw new Error("Invalid string. Length must be a multiple of 4")
|
|
|
- }
|
|
|
- return r[e - 2] === "=" ? 2 : r[e - 1] === "=" ? 1 : 0
|
|
|
- }
|
|
|
-
|
|
|
- function c(r) {
|
|
|
- return r.length * 3 / 4 - d(r)
|
|
|
- }
|
|
|
-
|
|
|
- function v(r) {
|
|
|
- var e, t, n, i, a;
|
|
|
- var u = r.length;
|
|
|
- i = d(r);
|
|
|
- a = new f(u * 3 / 4 - i);
|
|
|
- t = i > 0 ? u - 4 : u;
|
|
|
- var c = 0;
|
|
|
- for (e = 0; e < t; e += 4) {
|
|
|
- n = o[r.charCodeAt(e)] << 18 | o[r.charCodeAt(e + 1)] << 12 | o[r.charCodeAt(e +
|
|
|
- 2)] << 6 | o[r.charCodeAt(e + 3)];
|
|
|
- a[c++] = n >> 16 & 255;
|
|
|
- a[c++] = n >> 8 & 255;
|
|
|
- a[c++] = n & 255
|
|
|
- }
|
|
|
- if (i === 2) {
|
|
|
- n = o[r.charCodeAt(e)] << 2 | o[r.charCodeAt(e + 1)] >> 4;
|
|
|
- a[c++] = n & 255
|
|
|
- } else {
|
|
|
- if (i === 1) {
|
|
|
- n = o[r.charCodeAt(e)] << 10 | o[r.charCodeAt(e + 1)] << 4 | o[r.charCodeAt(
|
|
|
- e + 2)] >> 2;
|
|
|
- a[c++] = n >> 8 & 255;
|
|
|
- a[c++] = n & 255
|
|
|
- }
|
|
|
- }
|
|
|
- return a
|
|
|
- }
|
|
|
-
|
|
|
- function l(r) {
|
|
|
- return n[r >> 18 & 63] + n[r >> 12 & 63] + n[r >> 6 & 63] + n[r & 63]
|
|
|
- }
|
|
|
-
|
|
|
- function h(r, e, t) {
|
|
|
- var n;
|
|
|
- var o = [];
|
|
|
- for (var f = e; f < t; f += 3) {
|
|
|
- n = (r[f] << 16) + (r[f + 1] << 8) + r[f + 2];
|
|
|
- o.push(l(n))
|
|
|
- }
|
|
|
- return o.join("")
|
|
|
- }
|
|
|
-
|
|
|
- function s(r) {
|
|
|
- var e;
|
|
|
- var t = r.length;
|
|
|
- var o = t % 3;
|
|
|
- var f = "";
|
|
|
- var i = [];
|
|
|
- var a = 16383;
|
|
|
- for (var u = 0, d = t - o; u < d; u += a) {
|
|
|
- i.push(h(r, u, u + a > d ? d : u + a))
|
|
|
- }
|
|
|
- if (o === 1) {
|
|
|
- e = r[t - 1];
|
|
|
- f += n[e >> 2];
|
|
|
- f += n[e << 4 & 63];
|
|
|
- f += "=="
|
|
|
- } else {
|
|
|
- if (o === 2) {
|
|
|
- e = (r[t - 2] << 8) + r[t - 1];
|
|
|
- f += n[e >> 10];
|
|
|
- f += n[e >> 4 & 63];
|
|
|
- f += n[e << 2 & 63];
|
|
|
- f += "="
|
|
|
- }
|
|
|
- }
|
|
|
- i.push(f);
|
|
|
- return i.join("")
|
|
|
- }
|
|
|
- }, {}]
|
|
|
- }, {}, [])("/")
|
|
|
-});
|
|
|
-
|
|
|
-// const base64js = require('base64-js').Base64
|
|
|
+import CryptoJS from './crypto-js/crypto-js.js'
|
|
|
+var Base64 = Base64 || require('@/common/base64.js').Base64;
|
|
|
+import {
|
|
|
+ getToken
|
|
|
+} from './auth.js'
|
|
|
/**
|
|
|
* 国密SM4加密算法
|
|
|
*/
|
|
@@ -225,7 +72,6 @@ function SM4() {
|
|
|
return this.SHL(x, n) | x >> (32 - n);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
this.sm4Lt = function(ka) {
|
|
|
var bb = 0;
|
|
|
var c = 0;
|
|
@@ -260,8 +106,6 @@ function SM4() {
|
|
|
return rk;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
this.sm4Sbox = function(inch) {
|
|
|
var i = inch & 0xFF;
|
|
|
var retVal = SboxTable[i];
|
|
@@ -279,7 +123,6 @@ function SM4() {
|
|
|
}
|
|
|
ctx.mode = this.SM4_ENCRYPT;
|
|
|
this.sm4_setkey(ctx.sk, key);
|
|
|
-
|
|
|
};
|
|
|
//生成解密密钥
|
|
|
this.sm4_setkey_dec = function(ctx, key) {
|
|
@@ -291,7 +134,8 @@ function SM4() {
|
|
|
Error("key error!");
|
|
|
}
|
|
|
|
|
|
- ctx.mode = this.SM4_DECRYPT;
|
|
|
+ var i = 0;
|
|
|
+ ctx.mode = 0;
|
|
|
this.sm4_setkey(ctx.sk, key);
|
|
|
ctx.sk = ctx.sk.reverse();
|
|
|
}
|
|
@@ -351,13 +195,14 @@ function SM4() {
|
|
|
}
|
|
|
|
|
|
this.sm4_crypt_ecb = function(ctx, input) {
|
|
|
+
|
|
|
if (input == null) {
|
|
|
alert("input is null!");
|
|
|
}
|
|
|
+
|
|
|
if ((ctx.isPadding) && (ctx.mode == this.SM4_ENCRYPT)) {
|
|
|
input = this.padding(input, this.SM4_ENCRYPT);
|
|
|
}
|
|
|
-
|
|
|
var i = 0;
|
|
|
var length = input.length;
|
|
|
var bous = new Array();
|
|
@@ -368,7 +213,6 @@ function SM4() {
|
|
|
bous = bous.concat(out);
|
|
|
i++;
|
|
|
}
|
|
|
-
|
|
|
var output = bous;
|
|
|
if (ctx.isPadding && ctx.mode == this.SM4_DECRYPT) {
|
|
|
output = this.padding(output, this.SM4_DECRYPT);
|
|
@@ -420,7 +264,7 @@ function SM4() {
|
|
|
var out1 = new Array(16);
|
|
|
var ins = input.slice(k * 16, (16 * (k + 1)));
|
|
|
temp = ins.slice(0, 16);
|
|
|
- sm4_one_round(ctx.sk, ins, out);
|
|
|
+ this.sm4_one_round(ctx.sk, ins, out);
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
out1[i] = (out[i] ^ iv[i]);
|
|
|
}
|
|
@@ -444,13 +288,10 @@ function SM4() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
function SM4Util() {
|
|
|
-
|
|
|
- this.secretKey = "11HDESAAHIHHUGDZ";
|
|
|
- //this.iv = "UISwD9fW6cFh9SNS";
|
|
|
+ this.secretKey = "";
|
|
|
this.iv = "";
|
|
|
- //this.hexString = false;
|
|
|
+ this.hexString = false;
|
|
|
//加密_ECB
|
|
|
this.encryptData_ECB = function(plainText) {
|
|
|
try {
|
|
@@ -461,8 +302,7 @@ function SM4Util() {
|
|
|
var keyBytes = stringToByte(this.secretKey);
|
|
|
sm4.sm4_setkey_enc(ctx, keyBytes);
|
|
|
var encrypted = sm4.sm4_crypt_ecb(ctx, stringToByte(plainText));
|
|
|
-
|
|
|
- var cipherText = base64js.fromByteArray(encrypted);
|
|
|
+ var cipherText = Base64.fromUint8Array(encrypted);
|
|
|
if (cipherText != null && cipherText.trim().length > 0) {
|
|
|
cipherText.replace(/(\s*|\t|\r|\n)/g, "");
|
|
|
}
|
|
@@ -475,19 +315,30 @@ function SM4Util() {
|
|
|
}
|
|
|
//解密_ECB
|
|
|
this.decryptData_ECB = function(cipherText) {
|
|
|
- try {
|
|
|
- var sm4 = new SM4();
|
|
|
- var ctx = new SM4_Context();
|
|
|
- ctx.isPadding = true;
|
|
|
- ctx.mode = sm4.SM4_DECRYPT;
|
|
|
- var keyBytes = stringToByte(this.secretKey);
|
|
|
- sm4.sm4_setkey_dec(ctx, keyBytes);
|
|
|
- var decrypted = sm4.sm4_crypt_ecb(ctx, base64js.toByteArray(cipherText));
|
|
|
- return utf8ByteToUnicodeStr(decrypted);
|
|
|
- } catch (e) {
|
|
|
- console.log(e)
|
|
|
- console.error(e);
|
|
|
- return null;
|
|
|
+ if (cipherText) {
|
|
|
+ try {
|
|
|
+ var sm4 = new SM4();
|
|
|
+ var ctx = new SM4_Context();
|
|
|
+ ctx.isPadding = true;
|
|
|
+ ctx.mode = sm4.SM4_ENCRYPT;
|
|
|
+ var keyBytes = stringToByte(this.secretKey);
|
|
|
+ sm4.sm4_setkey_dec(ctx, keyBytes);
|
|
|
+ if (typeof cipherText === 'string') {
|
|
|
+ var decrypted = sm4.sm4_crypt_ecb(ctx, Base64.toUint8Array(cipherText));
|
|
|
+ return byteToString(decrypted);
|
|
|
+ } else if (cipherText instanceof Array) {
|
|
|
+ let decrypted = []
|
|
|
+ cipherText.forEach((item) => {
|
|
|
+ let str = sm4.sm4_crypt_ecb(ctx, Base64.toUint8Array(item))
|
|
|
+ decrypted.push(byteToString(str))
|
|
|
+ })
|
|
|
+ return decrypted;
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (e) {
|
|
|
+ console.error(e);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -503,7 +354,7 @@ function SM4Util() {
|
|
|
|
|
|
sm4.sm4_setkey_enc(ctx, keyBytes);
|
|
|
var encrypted = sm4.sm4_crypt_cbc(ctx, ivBytes, stringToByte(plainText));
|
|
|
- var cipherText = base64js.fromByteArray(encrypted);
|
|
|
+ var cipherText = Base64.fromUint8Array(encrypted);
|
|
|
if (cipherText != null && cipherText.trim().length > 0) {
|
|
|
cipherText.replace(/(\s*|\t|\r|\n)/g, "");
|
|
|
}
|
|
@@ -513,8 +364,25 @@ function SM4Util() {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
+ //解密_CBC
|
|
|
+ this.decryptData_CBC = function(cipherText) {
|
|
|
+ try {
|
|
|
+ var sm4 = new SM4();
|
|
|
+ var ctx = new SM4_Context();
|
|
|
+ ctx.isPadding = true;
|
|
|
+ ctx.mode = sm4.SM4_ENCRYPT;
|
|
|
+ var keyBytes = stringToByte(this.secretKey);
|
|
|
+ var ivBytes = stringToByte(this.iv);
|
|
|
+ sm4.sm4_setkey_dec(ctx, keyBytes);
|
|
|
+ var decrypted = sm4.sm4_crypt_cbc(ctx, ivBytes, Base64.toUint8Array(cipherText));
|
|
|
+ return byteToString(decrypted);
|
|
|
+ } catch (e) {
|
|
|
+ console.error(e);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- var stringToByte = function(str) {
|
|
|
+ function stringToByte(str) {
|
|
|
var bytes = new Array();
|
|
|
var len, c;
|
|
|
len = str.length;
|
|
@@ -535,14 +403,11 @@ function SM4Util() {
|
|
|
} else {
|
|
|
bytes.push(c & 0xFF);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
- // console.log('bytes: '+bytes)
|
|
|
return bytes;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- var byteToString = function(arr) {
|
|
|
+ function byteToString(arr) {
|
|
|
if (typeof arr === 'string') {
|
|
|
return arr;
|
|
|
}
|
|
@@ -555,7 +420,9 @@ function SM4Util() {
|
|
|
var bytesLength = v[0].length;
|
|
|
var store = _arr[i].toString(2).slice(7 - bytesLength);
|
|
|
for (var st = 1; st < bytesLength; st++) {
|
|
|
- store += _arr[st + i].toString(2).slice(2);
|
|
|
+ if (_arr[st + i]) {
|
|
|
+ store += _arr[st + i].toString(2).slice(2);
|
|
|
+ }
|
|
|
}
|
|
|
str += String.fromCharCode(parseInt(store, 2));
|
|
|
i += bytesLength - 1;
|
|
@@ -565,64 +432,228 @@ function SM4Util() {
|
|
|
}
|
|
|
return str;
|
|
|
}
|
|
|
+};
|
|
|
|
|
|
- function utf8ByteToUnicodeStr(utf8Bytes) {
|
|
|
- var unicodeStr = "";
|
|
|
- for (var pos = 0; pos < utf8Bytes.length;) {
|
|
|
- var flag = utf8Bytes[pos];
|
|
|
- var unicode = 0;
|
|
|
- if ((flag >>> 7) === 0) {
|
|
|
- unicodeStr += String.fromCharCode(utf8Bytes[pos]);
|
|
|
- pos += 1;
|
|
|
-
|
|
|
- } else if ((flag & 0xFC) === 0xFC) {
|
|
|
- unicode = (utf8Bytes[pos] & 0x3) << 30;
|
|
|
- unicode |= (utf8Bytes[pos + 1] & 0x3F) << 24;
|
|
|
- unicode |= (utf8Bytes[pos + 2] & 0x3F) << 18;
|
|
|
- unicode |= (utf8Bytes[pos + 3] & 0x3F) << 12;
|
|
|
- unicode |= (utf8Bytes[pos + 4] & 0x3F) << 6;
|
|
|
- unicode |= (utf8Bytes[pos + 5] & 0x3F);
|
|
|
- unicodeStr += String.fromCharCode(unicode);
|
|
|
- pos += 6;
|
|
|
-
|
|
|
- } else if ((flag & 0xF8) === 0xF8) {
|
|
|
- unicode = (utf8Bytes[pos] & 0x7) << 24;
|
|
|
- unicode |= (utf8Bytes[pos + 1] & 0x3F) << 18;
|
|
|
- unicode |= (utf8Bytes[pos + 2] & 0x3F) << 12;
|
|
|
- unicode |= (utf8Bytes[pos + 3] & 0x3F) << 6;
|
|
|
- unicode |= (utf8Bytes[pos + 4] & 0x3F);
|
|
|
- unicodeStr += String.fromCharCode(unicode);
|
|
|
- pos += 5;
|
|
|
-
|
|
|
- } else if ((flag & 0xF0) === 0xF0) {
|
|
|
- unicode = (utf8Bytes[pos] & 0xF) << 18;
|
|
|
- unicode |= (utf8Bytes[pos + 1] & 0x3F) << 12;
|
|
|
- unicode |= (utf8Bytes[pos + 2] & 0x3F) << 6;
|
|
|
- unicode |= (utf8Bytes[pos + 3] & 0x3F);
|
|
|
- unicodeStr += String.fromCharCode(unicode);
|
|
|
- pos += 4;
|
|
|
-
|
|
|
- } else if ((flag & 0xE0) === 0xE0) {
|
|
|
- unicode = (utf8Bytes[pos] & 0x1F) << 12;;
|
|
|
- unicode |= (utf8Bytes[pos + 1] & 0x3F) << 6;
|
|
|
- unicode |= (utf8Bytes[pos + 2] & 0x3F);
|
|
|
- unicodeStr += String.fromCharCode(unicode);
|
|
|
- pos += 3;
|
|
|
-
|
|
|
- } else if ((flag & 0xC0) === 0xC0) { //110
|
|
|
- unicode = (utf8Bytes[pos] & 0x3F) << 6;
|
|
|
- unicode |= (utf8Bytes[pos + 1] & 0x3F);
|
|
|
- unicodeStr += String.fromCharCode(unicode);
|
|
|
- pos += 2;
|
|
|
+function getsm4Key() {
|
|
|
+ var token = getToken()
|
|
|
+ if (token == null || token.length == 0) token = '1234567887654321'
|
|
|
+ return CryptoJS.MD5(token).toString().toUpperCase().substr(16, 16)
|
|
|
+}
|
|
|
|
|
|
+function getsm4Iv() {
|
|
|
+ var token = getToken()
|
|
|
+ if (token == null || token.length == 0) token = '1234567887654321'
|
|
|
+ return CryptoJS.MD5(CryptoJS.MD5(token).toString()).toString().toUpperCase().substr(16, 16)
|
|
|
+}
|
|
|
+
|
|
|
+function getsm4Keydef() {
|
|
|
+ var token = '1234567887654321'
|
|
|
+ return token
|
|
|
+}
|
|
|
+
|
|
|
+function getsm4Ivdef() {
|
|
|
+ var token = '1234567887654321'
|
|
|
+ return CryptoJS.MD5(CryptoJS.MD5(token).toString()).toString().toUpperCase().substr(16, 16)
|
|
|
+}
|
|
|
+
|
|
|
+function maskA(str, cd) {
|
|
|
+ let cdc = str.length - 2 * cd;
|
|
|
+ if (cdc > 0) {
|
|
|
+ var reptext = ''
|
|
|
+ for (let k = 0; k < cdc; k++) {
|
|
|
+ reptext = reptext + '✱'
|
|
|
+ }
|
|
|
+ return str.substr(0, cd) + reptext + str.substr(str.length - cd);
|
|
|
+ } else
|
|
|
+ return str;
|
|
|
+}
|
|
|
+
|
|
|
+function mask(str, type) {
|
|
|
+ return str;
|
|
|
+ let strcd = str != null ? str.length : 0;
|
|
|
+ if (strcd > 0) {
|
|
|
+ if (type == 1) //姓名
|
|
|
+ {
|
|
|
+ if (strcd > 1) {
|
|
|
+ let cdc = strcd - 1;
|
|
|
+ var reptext = ''
|
|
|
+ for (let k = 0; k < cdc; k++) {
|
|
|
+ reptext = reptext + '✱'
|
|
|
+ }
|
|
|
+ return reptext + str.substr(cdc)
|
|
|
} else {
|
|
|
- unicodeStr += String.fromCharCode(utf8Bytes[pos]);
|
|
|
- pos += 1;
|
|
|
+ return str
|
|
|
}
|
|
|
+ } else if (type == 2) //身份证号
|
|
|
+ {
|
|
|
+ if (strcd == 18) {
|
|
|
+ return str.substr(0, 3) + '✱✱✱✱✱' + str.substr(8, 1) + '✱✱✱✱✱✱✱' + str.substr(16, 1) + '✱';
|
|
|
+ } else {
|
|
|
+ return maskA(str, 1);
|
|
|
+ }
|
|
|
+ } else if (type == 3) //手机号
|
|
|
+ {
|
|
|
+ if (strcd == 11) {
|
|
|
+ return str.substr(0, 2) + '✱✱✱✱✱✱✱✱' + str.substr(10, 1);
|
|
|
+ } else {
|
|
|
+ return maskA(str, 2);
|
|
|
+ }
|
|
|
+ } else if (type == 4) //住址
|
|
|
+ {
|
|
|
+ return maskA(str, 2);
|
|
|
+ } else if (type == 5) //邮件地址
|
|
|
+ {
|
|
|
+ return maskA(str, 2);
|
|
|
+ } else if (type == 6) {
|
|
|
+ return maskA(str, 1);
|
|
|
+ } else //其他
|
|
|
+ {
|
|
|
+ return str;
|
|
|
}
|
|
|
- return unicodeStr;
|
|
|
+ } else {
|
|
|
+ return str
|
|
|
}
|
|
|
-};
|
|
|
-module.exports = {
|
|
|
- s4: new SM4Util()
|
|
|
+}
|
|
|
+
|
|
|
+function maskArr(arr, type) {
|
|
|
+ return arr;
|
|
|
+ let res = []
|
|
|
+ arr.forEach((str) => {
|
|
|
+ let strcd = str != null ? str.length : 0;
|
|
|
+ if (strcd > 0) {
|
|
|
+ if (type == 1) //姓名
|
|
|
+ {
|
|
|
+ if (strcd > 1) {
|
|
|
+ let cdc = strcd - 1;
|
|
|
+ var reptext = ''
|
|
|
+ for (let k = 0; k < cdc; k++) {
|
|
|
+ reptext = reptext + '✱'
|
|
|
+ }
|
|
|
+ res.push(reptext + str.substr(cdc))
|
|
|
+ } else {
|
|
|
+ res.push(str)
|
|
|
+ }
|
|
|
+ } else if (type == 2) //身份证号
|
|
|
+ {
|
|
|
+ if (strcd == 18) {
|
|
|
+ res.push(str.substr(0, 3) + '✱✱✱✱✱' + str.substr(8, 1) + '✱✱✱✱✱✱✱' + str.substr(16, 1) +
|
|
|
+ '✱')
|
|
|
+ } else {
|
|
|
+ res.push(maskA(str, 1))
|
|
|
+ }
|
|
|
+ } else if (type == 3) //手机号
|
|
|
+ {
|
|
|
+ if (strcd == 11) {
|
|
|
+ res.push(str.substr(0, 2) + '✱✱✱✱✱✱✱✱' + str.substr(10, 1))
|
|
|
+ } else {
|
|
|
+ res.push(maskA(str, 2))
|
|
|
+ }
|
|
|
+ } else if (type == 4) //住址
|
|
|
+ {
|
|
|
+ res.push(maskA(str, 2))
|
|
|
+ } else if (type == 5) //邮件地址
|
|
|
+ {
|
|
|
+ res.push(maskA(str, 2))
|
|
|
+ } else if (type == 6) //邮件地址
|
|
|
+ {
|
|
|
+ res.push(maskA(str, 1))
|
|
|
+ } else {
|
|
|
+ res.push(str)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ res.push(str)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return res
|
|
|
+}
|
|
|
+
|
|
|
+export function encrypt_ECB(data) {
|
|
|
+ var s4 = new SM4Util();
|
|
|
+ s4.secretKey = getsm4Key();
|
|
|
+ return s4.encryptData_ECB(data);
|
|
|
+}
|
|
|
+
|
|
|
+export function encrypt_ECBdef(data) {
|
|
|
+ var s4 = new SM4Util();
|
|
|
+ s4.secretKey = getsm4Keydef();
|
|
|
+ return s4.encryptData_ECB(data);
|
|
|
+}
|
|
|
+export function encrypt_ECBA(data, key) {
|
|
|
+ var s4 = new SM4Util();
|
|
|
+ s4.secretKey = key;
|
|
|
+ return s4.encryptData_ECB(data);
|
|
|
+}
|
|
|
+export function decrypt_ECB(data) {
|
|
|
+ var s4 = new SM4Util();
|
|
|
+ s4.secretKey = getsm4Key();
|
|
|
+ return s4.decryptData_ECB(data);
|
|
|
+}
|
|
|
+
|
|
|
+export function decrypt_ECBdef(data) {
|
|
|
+ var s4 = new SM4Util();
|
|
|
+ s4.secretKey = getsm4Keydef();
|
|
|
+ return s4.decryptData_ECB(data);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+export function masks(str, type) {
|
|
|
+ return mask(str, type);
|
|
|
+}
|
|
|
+
|
|
|
+export function encrypt_CBC(data) {
|
|
|
+ var s4 = new SM4Util();
|
|
|
+ s4.secretKey = getsm4Key();
|
|
|
+ s4.iv = getsm4Iv();
|
|
|
+ return s4.encryptData_CBC(data);
|
|
|
+}
|
|
|
+export function encrypt_CBCdef(data) {
|
|
|
+ var s4 = new SM4Util();
|
|
|
+ s4.secretKey = getsm4Keydef();
|
|
|
+ s4.iv = getsm4Ivdef();
|
|
|
+ return s4.encryptData_CBC(data);
|
|
|
+}
|
|
|
+export function decrypt_CBC(data) {
|
|
|
+ var s4 = new SM4Util();
|
|
|
+ s4.secretKey = getsm4Key();
|
|
|
+ s4.iv = getsm4Iv();
|
|
|
+ return s4.decryptData_CBC(data);
|
|
|
+}
|
|
|
+export function decrypt_CBCdef(data) {
|
|
|
+ var s4 = new SM4Util();
|
|
|
+ s4.secretKey = getsm4Keydef();
|
|
|
+ s4.iv = getsm4Ivdef();
|
|
|
+ return s4.decryptData_CBC(data);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+export function decryptData_ECB(rowdata, fields, hides) {
|
|
|
+ if (rowdata) {
|
|
|
+ var s4 = new SM4Util();
|
|
|
+ s4.secretKey = getsm4Key();
|
|
|
+ for (let j = 0; j < fields.length; j++) {
|
|
|
+ if (rowdata[fields[j]] != null) {
|
|
|
+ let zfc = s4.decryptData_ECB(rowdata[fields[j]]);
|
|
|
+ zfc instanceof Array ? rowdata[fields[j]] = maskArr(zfc, hides[j]) : rowdata[fields[j]] = mask(zfc,
|
|
|
+ hides[j])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return rowdata
|
|
|
+}
|
|
|
+
|
|
|
+export function decryptRowData_ECB(rowdata, fields, hides) {
|
|
|
+ if (rowdata && rowdata.length > 0) {
|
|
|
+ var s4 = new SM4Util();
|
|
|
+ s4.secretKey = getsm4Key();
|
|
|
+ for (let i = 0; i < rowdata.length; i++) {
|
|
|
+ for (let j = 0; j < fields.length; j++) {
|
|
|
+ if (rowdata[i][fields[j]] != null) {
|
|
|
+ let srcs = rowdata[i][fields[j]]
|
|
|
+ let zfc = s4.decryptData_ECB(srcs);
|
|
|
+ rowdata[i][fields[j]] = mask(zfc, hides[j]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return rowdata
|
|
|
}
|