@tugou/baimahu
Advanced tools
+0
-1
@@ -6,2 +6,1 @@ export { BaimahuConfiguration as Configuration } from './configuration'; | ||
| export * from './lib/param'; | ||
| export * from './lib/crypto'; |
+0
-1
@@ -20,2 +20,1 @@ "use strict"; | ||
| __exportStar(require("./lib/param"), exports); | ||
| __exportStar(require("./lib/crypto"), exports); |
+2
-2
| { | ||
| "name": "@tugou/baimahu", | ||
| "version": "2.2.3", | ||
| "version": "2.2.4", | ||
| "description": "标准函数扩展-前后端通用", | ||
@@ -19,3 +19,3 @@ "main": "dist/index", | ||
| "license": "MIT", | ||
| "gitHead": "bf571d3dc4c9ea3332a04edc4d407ba165bca320", | ||
| "gitHead": "9d56520dba9df9a0fc7594cc21bea3f10ac4b457", | ||
| "dependencies": { | ||
@@ -22,0 +22,0 @@ "crypto": "^1.0.1" |
| export declare class Crypto { | ||
| private config; | ||
| encrypt(value: any): any; | ||
| decrypt(value: any): any; | ||
| md5(value: any): any; | ||
| md5Salt(value: any): any; | ||
| } |
| "use strict"; | ||
| var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
| var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
| if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
| else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
| return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
| }; | ||
| var __metadata = (this && this.__metadata) || function (k, v) { | ||
| if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.Crypto = void 0; | ||
| const decorator_1 = require("@midwayjs/decorator"); | ||
| const crypto = require('crypto'); | ||
| let Crypto = class Crypto { | ||
| encrypt(value) { | ||
| const { aes } = this.config; | ||
| const cipher = crypto.createCipheriv(aes.algorithm, aes.key, aes.iv); | ||
| let crypted = cipher.update(JSON.stringify(value), 'binary', 'base64'); | ||
| crypted += cipher.final('base64'); | ||
| return crypted; | ||
| } | ||
| decrypt(value) { | ||
| const { aes } = this.config; | ||
| const decipher = crypto.createDecipheriv(aes.algorithm, aes.key, aes.iv); | ||
| let decrypted = decipher.update(value, 'base64', 'binary'); | ||
| decrypted += decipher.final('binary'); | ||
| decrypted = JSON.parse(decrypted); | ||
| return decrypted; | ||
| } | ||
| md5(value) { | ||
| return crypto.createHash('md5').update(value).digest('hex'); | ||
| } | ||
| md5Salt(value) { | ||
| const { salt } = this.config; | ||
| return this.md5(value + salt); | ||
| } | ||
| }; | ||
| __decorate([ | ||
| decorator_1.Config('crypto'), | ||
| __metadata("design:type", Object) | ||
| ], Crypto.prototype, "config", void 0); | ||
| Crypto = __decorate([ | ||
| decorator_1.Provide(), | ||
| decorator_1.Scope(decorator_1.ScopeEnum.Singleton) | ||
| ], Crypto); | ||
| exports.Crypto = Crypto; |
10486
-17.96%13
-13.33%332
-14.43%