UNPKG

3.07 kBJavaScriptView Raw
1"use strict";
2var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5 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;
6 return c > 3 && r && Object.defineProperty(target, key, r), r;
7};
8var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9 return new (P || (P = Promise))(function (resolve, reject) {
10 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
13 step((generator = generator.apply(thisArg, _arguments || [])).next());
14 });
15};
16Object.defineProperty(exports, "__esModule", { value: true });
17const common_1 = require("@nestjs/common");
18const Chance = require("chance");
19const crypto = require("crypto");
20let ParamUtil = class ParamUtil {
21 findSameTemplateId(template) {
22 return __awaiter(this, void 0, void 0, function* () {
23 const existTemplateId = [];
24 const templateIds = template.map(item => item.templateId);
25 templateIds.forEach(item => { (templateIds.indexOf(item) !== templateIds.lastIndexOf(item) && existTemplateId.indexOf(item) === -1) && existTemplateId.push(item); });
26 return existTemplateId;
27 });
28 }
29 genValidationCode() {
30 return __awaiter(this, void 0, void 0, function* () {
31 return new Chance().natural({ min: 100000, max: 999999 });
32 });
33 }
34 encryptor(aesKey, original) {
35 return __awaiter(this, void 0, void 0, function* () {
36 const key = crypto.createHash("sha256").update(aesKey).digest();
37 const iv = key.slice(0, 16);
38 const cipher = crypto.createCipheriv("aes-256-cbc", key, iv);
39 const cipherText = Buffer.concat([cipher.update(Buffer.from(original)), cipher.final()]);
40 return cipherText.toString("base64");
41 });
42 }
43 decryptor(aesKey, cipherText) {
44 return __awaiter(this, void 0, void 0, function* () {
45 const key = crypto.createHash("sha256").update(aesKey).digest();
46 const iv = key.slice(0, 16);
47 const decipher = crypto.createDecipheriv("aes-256-cbc", key, iv);
48 const original = Buffer.concat([decipher.update(cipherText, "base64"), decipher.final()]);
49 return original.toString();
50 });
51 }
52};
53ParamUtil = __decorate([
54 common_1.Injectable()
55], ParamUtil);
56exports.ParamUtil = ParamUtil;
57
58//# sourceMappingURL=param.util.js.map