Commit a094d5c3 by Sxy

feat: 加密

parent c437214a
...@@ -2,6 +2,8 @@ var fs = require("fs"); ...@@ -2,6 +2,8 @@ var fs = require("fs");
var objsettings = require("../config/objsettings"); var objsettings = require("../config/objsettings");
var settings = require("../config/settings"); var settings = require("../config/settings");
const request = require('request'); const request = require('request');
const cryptoJS = require('crypto-js');
class System { class System {
static declare(ns) { static declare(ns) {
var ar = ns.split('.'); var ar = ns.split('.');
...@@ -298,6 +300,37 @@ class System { ...@@ -298,6 +300,37 @@ class System {
return P return P
} }
/**
* 加密信息
* @param {*} opStr
*/
static encryptStr(opStr) {
if (!opStr) {
return opStr;
}
let keyHex = cryptoJS.enc.Utf8.parse(settings.encrypt_key);
let ivHex = cryptoJS.enc.Utf8.parse(settings.encrypt_secret.substring(0, 8));
var cipherStr = cryptoJS.TripleDES.encrypt(opStr, keyHex, { iv: ivHex }).toString();
return cipherStr;
}
/**
* 解密信息
* @param {*} opStr
*/
static decryptStr(opStr) {
if (!opStr) {
return opStr;
}
let keyHex = cryptoJS.enc.Utf8.parse(settings.encrypt_key);
let ivHex = cryptoJS.enc.Utf8.parse(settings.encrypt_secret.substring(0, 8));
var bytes = cryptoJS.TripleDES.decrypt(opStr, keyHex, {
iv: ivHex
});
var plaintext = bytes.toString(cryptoJS.enc.Utf8);
return plaintext;
}
} }
Date.prototype.Format = function (fmt) { //author: meizz Date.prototype.Format = function (fmt) { //author: meizz
var o = { var o = {
......
...@@ -9,7 +9,9 @@ var ENVINPUT = { ...@@ -9,7 +9,9 @@ var ENVINPUT = {
REDIS_PORT: process.env.REDIS_PORT, REDIS_PORT: process.env.REDIS_PORT,
REDIS_PWD: process.env.REDIS_PWD, REDIS_PWD: process.env.REDIS_PWD,
REDIS_DB: process.env.PAAS_REDIS_DB, REDIS_DB: process.env.PAAS_REDIS_DB,
APP_ENV: process.env.APP_ENV ? process.env.APP_ENV : "localhost" APP_ENV: process.env.APP_ENV ? process.env.APP_ENV : "localhost",
ENCRYPT_KEY: process.env.ENCRYPT_KEY ? process.env.ENCRYPT_KEY : "202007211106",
ENCRYPT_SECRET: process.env.ENCRYPT_SECRET ? process.env.ENCRYPT_SECRET : "scbb846246874887b5c7e01cd0816c66"
}; };
var settings = { var settings = {
env: ENVINPUT.APP_ENV, env: ENVINPUT.APP_ENV,
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
"continuation-local-storage": "^3.2.1", "continuation-local-storage": "^3.2.1",
"cookie-parser": "^1.4.3", "cookie-parser": "^1.4.3",
"crypto": "^1.0.1", "crypto": "^1.0.1",
"crypto-js": "^3.1.9-1", "crypto-js": "^3.3.0",
"easyimage": "^3.1.0", "easyimage": "^3.1.0",
"ejs": "^2.5.8", "ejs": "^2.5.8",
"engine.io-parser": "^2.1.2", "engine.io-parser": "^2.1.2",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment