first commit

This commit is contained in:
编码猿
2024-09-27 02:06:13 +08:00
commit 852d94fbb9
36760 changed files with 3274413 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
const config = require("../config")
const rsa = require("../utils/rsa")
const jwt = require('jsonwebtoken')
/**
* 拦截器,验证 tokendata
* @type {{Validator(*, *, *): void}}
*/
module.exports = {
Validator(req, res, next) {
next()
// if(req.headers.hasOwnProperty("data")) {
// try {
// req.headers.data = rsa.PrivateKeyDecryption(req.headers.data)
// if (req.url == config.filter.login || req.url == config.filter.add) {
// next()
// } else {
// if (req.headers.hasOwnProperty("token")) {
// jwt.verify(req.headers.token, config.jwt, function (err, decode) {
// if (err) {
// res.json({
// status: 500,
// message: '身份凭证失效或不存在,请登录'
// })
// } else {
// next();
// }
// });
// } else { // 无token
// res.json({
// status: 500,
// message: '缺少token参数请检查'
// })
// }
// }
// } catch (e) {
// res.json({
// status: 500,
// message: '抱歉,公钥加密有误,请检查公钥'
// })
// }
// } else {
// res.json({
// status: 500,
// message: '请求头缺少data参数'
// })
// }
}
}

View File

@@ -0,0 +1,18 @@
var md5 = require("md5");
class Utils {
Md5Password(str){
return md5(str);
}
getTime(){
var year = new Date().getFullYear();
var month = new Date().getMonth()+1;
var day = new Date().getDate();
var hour = new Date().getHours();
var minute = new Date().getMinutes();
return `${year}${month}${day}${hour}:${minute}`
}
}
module.exports = new Utils()

View File

@@ -0,0 +1,53 @@
const NodeRsa = require("node-rsa");
const fs = require("fs");
const path = require("path");
const config = require("../config");
class Rsa {
constructor() {
this.private_key = this.readFiles(this.getFilePath(config.rsa.private_key))
this.public_key = this.readFiles(this.getFilePath(config.rsa.public_key))
}
// 公钥加密
PublicKeyEncryption(text) {
return (new NodeRsa(this.public_key)).encrypt(JSON.stringify(text), 'base64')
}
// 公钥解密
PublicKeyDecryption(text) {
return JSON.parse((new NodeRsa(this.public_key)).decryptPublic(text, 'utf8'))
}
// 私钥加密
PrivateKeyEncryption(text) {
return (new NodeRsa(this.private_key)).encryptPrivate(JSON.stringify(text), 'base64')
}
// 私钥解密
PrivateKeyDecryption(text) {
return JSON.parse((new NodeRsa(this.private_key)).decrypt(text, 'utf8'))
}
/**
* 获取path.join文件地址
* @param paths
* @returns {string}
*/
getFilePath(paths) {
return path.join(__dirname, paths)
}
/**
* 读取文件数据
* @param path
* @returns {*}
*/
readFiles(path) {
return fs.readFileSync(path).toString()
}
}
module.exports = new Rsa();