mfance-shark-v1 1.0.24 → 1.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export declare class CryptoService {
|
|
2
|
-
private
|
|
3
|
-
private
|
|
4
|
-
|
|
2
|
+
private privateKey;
|
|
3
|
+
private publicKey;
|
|
4
|
+
private path;
|
|
5
|
+
constructor();
|
|
6
|
+
setPath(path: string): this;
|
|
7
|
+
loadKeys(): this;
|
|
5
8
|
encryptData(data: string): string;
|
|
6
9
|
decryptData(encryptedData: string): string;
|
|
7
10
|
}
|
|
@@ -14,24 +14,39 @@ const common_1 = require("@nestjs/common");
|
|
|
14
14
|
const fs = require("fs");
|
|
15
15
|
const crypto = require("crypto");
|
|
16
16
|
let CryptoService = class CryptoService {
|
|
17
|
-
constructor(
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
constructor() {
|
|
18
|
+
}
|
|
19
|
+
setPath(path) {
|
|
20
|
+
this.path = path;
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
loadKeys() {
|
|
24
|
+
this.privateKey = fs.readFileSync(this.path + '/private.pem', 'utf8');
|
|
25
|
+
this.publicKey = fs.readFileSync(this.path + '/public.pem', 'utf8');
|
|
26
|
+
return this;
|
|
20
27
|
}
|
|
21
28
|
encryptData(data) {
|
|
22
29
|
const buffer = Buffer.from(data, 'utf8');
|
|
23
|
-
const encrypted = crypto.publicEncrypt(
|
|
30
|
+
const encrypted = crypto.publicEncrypt({
|
|
31
|
+
key: this.publicKey,
|
|
32
|
+
padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,
|
|
33
|
+
oaepHash: 'sha256'
|
|
34
|
+
}, buffer);
|
|
24
35
|
return encrypted.toString('base64');
|
|
25
36
|
}
|
|
26
37
|
decryptData(encryptedData) {
|
|
27
38
|
const buffer = Buffer.from(encryptedData, 'base64');
|
|
28
|
-
const decrypted = crypto.privateDecrypt(
|
|
39
|
+
const decrypted = crypto.privateDecrypt({
|
|
40
|
+
key: this.privateKey,
|
|
41
|
+
padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,
|
|
42
|
+
oaepHash: 'sha256'
|
|
43
|
+
}, buffer);
|
|
29
44
|
return decrypted.toString('utf8');
|
|
30
45
|
}
|
|
31
46
|
};
|
|
32
47
|
exports.CryptoService = CryptoService;
|
|
33
48
|
exports.CryptoService = CryptoService = __decorate([
|
|
34
49
|
(0, common_1.Injectable)(),
|
|
35
|
-
__metadata("design:paramtypes", [
|
|
50
|
+
__metadata("design:paramtypes", [])
|
|
36
51
|
], CryptoService);
|
|
37
52
|
//# sourceMappingURL=cryptoService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cryptoService.js","sourceRoot":"","sources":["../../../src/services/crypto/cryptoService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,yBAAyB;AACzB,iCAAiC;AAG1B,IAAM,aAAa,GAAnB,MAAM,aAAa;
|
|
1
|
+
{"version":3,"file":"cryptoService.js","sourceRoot":"","sources":["../../../src/services/crypto/cryptoService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,yBAAyB;AACzB,iCAAiC;AAG1B,IAAM,aAAa,GAAnB,MAAM,aAAa;IAKxB;IAEA,CAAC;IAGD,OAAO,CAAC,IAAY;QAClB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,QAAQ;QACN,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,GAAG,cAAc,EAAE,MAAM,CAAC,CAAC;QACtE,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,GAAG,aAAa,EAAE,MAAM,CAAC,CAAC;QACpE,OAAO,IAAI,CAAC;IACd,CAAC;IAGD,WAAW,CAAC,IAAY;Q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