@meebon/meebon-crypto 1.2.21 → 1.2.22
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.
|
@@ -6,6 +6,6 @@ import { MeebonCryptoKeyPair } from '../types/global';
|
|
|
6
6
|
* @param {MeebonCryptoKeyPair} keys - An object containing the privateKey, publicKey, and forRequest flag.
|
|
7
7
|
* @returns {RequestHandler} The Express middleware function.
|
|
8
8
|
*/
|
|
9
|
-
declare function EncryptionMiddleware({ privateKey, publicKey
|
|
9
|
+
declare function EncryptionMiddleware({ privateKey, publicKey }: MeebonCryptoKeyPair): RequestHandler;
|
|
10
10
|
export { EncryptionMiddleware };
|
|
11
11
|
//# sourceMappingURL=ExpressEncryptionMiddleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpressEncryptionMiddleware.d.ts","sourceRoot":"","sources":["../lib/ExpressEncryptionMiddleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAmC,cAAc,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD;;;;;GAKG;AACH,iBAAS,oBAAoB,CAAC,EAAE,UAAU,EAAE,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"ExpressEncryptionMiddleware.d.ts","sourceRoot":"","sources":["../lib/ExpressEncryptionMiddleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAmC,cAAc,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD;;;;;GAKG;AACH,iBAAS,oBAAoB,CAAC,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,mBAAmB,GAAG,cAAc,CAiC5F;AAED,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
|
package/dist/MeebonCrypto.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import forge from 'node-forge';
|
|
2
|
-
import {
|
|
2
|
+
import { MeebonCryptoKeyPair, MeebonCryptoProps } from '../types/global';
|
|
3
3
|
export declare class MeebonCrypto {
|
|
4
4
|
protected privateKeyPem: string;
|
|
5
5
|
protected publicKeyPem: string;
|
|
@@ -29,9 +29,9 @@ export declare class MeebonCrypto {
|
|
|
29
29
|
* Generates an RSA key pair with the specified key size.
|
|
30
30
|
*
|
|
31
31
|
* @param {number} [length=3072] - The length of the RSA key in bits (defaults to 3072).
|
|
32
|
-
* @returns {
|
|
32
|
+
* @returns {MeebonCryptoKeyPair} An object containing the generated public and private keys in PEM format.
|
|
33
33
|
*/
|
|
34
|
-
static generateKeyPair(length?: number):
|
|
34
|
+
static generateKeyPair(length?: number): MeebonCryptoKeyPair;
|
|
35
35
|
/**
|
|
36
36
|
* Encrypts data with a provided public key.
|
|
37
37
|
* @param {string} data - The data to encrypt.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MeebonCrypto.d.ts","sourceRoot":"","sources":["../lib/MeebonCrypto.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"MeebonCrypto.d.ts","sourceRoot":"","sources":["../lib/MeebonCrypto.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzE,qBAAa,YAAY;IACvB,SAAS,CAAC,aAAa,EAAE,MAAM,CAAC;IAChC,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC;IAExB,UAAU,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC;IACrC,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC;IAE1C,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,gBAAgB,CAAC;IAEjD,OAAO;IASP;;;;OAIG;WACW,IAAI,CAAC,KAAK,EAAE,iBAAiB,GAAG,YAAY;IAI1D;;;;OAIG;IACI,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;IAKzC;;;;OAIG;IACI,OAAO,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM;IAK7C;;;;;OAKG;WACW,eAAe,CAAC,MAAM,GAAE,MAAa,GAAG,mBAAmB;IAQzE;;;;;;OAMG;WACW,WAAW,CACvB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,MAAM,GAAE,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,gBAA6B,GAClD,MAAM;IAMT;;;;;;OAMG;WACW,WAAW,CACvB,aAAa,EAAE,MAAM,EACrB,UAAU,EAAE,MAAM,EAClB,MAAM,GAAE,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,gBAA6B,GAClD,MAAM;CAKV"}
|
package/dist/index.js
CHANGED
|
@@ -43,7 +43,7 @@ var MeebonCrypto = class _MeebonCrypto {
|
|
|
43
43
|
* Generates an RSA key pair with the specified key size.
|
|
44
44
|
*
|
|
45
45
|
* @param {number} [length=3072] - The length of the RSA key in bits (defaults to 3072).
|
|
46
|
-
* @returns {
|
|
46
|
+
* @returns {MeebonCryptoKeyPair} An object containing the generated public and private keys in PEM format.
|
|
47
47
|
*/
|
|
48
48
|
static generateKeyPair(length = 3072) {
|
|
49
49
|
const keyPair = forge.pki.rsa.generateKeyPair({ bits: length, e: 65537 });
|
|
@@ -79,37 +79,33 @@ var MeebonCrypto = class _MeebonCrypto {
|
|
|
79
79
|
};
|
|
80
80
|
|
|
81
81
|
// lib/ExpressEncryptionMiddleware.ts
|
|
82
|
-
function EncryptionMiddleware({ privateKey, publicKey
|
|
82
|
+
function EncryptionMiddleware({ privateKey, publicKey }) {
|
|
83
83
|
return (req, res, next) => {
|
|
84
|
-
if (
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
} catch (error) {
|
|
91
|
-
next(new Error(error?.message || "Encryption failed."));
|
|
92
|
-
}
|
|
84
|
+
if (req.body && req.body.data) {
|
|
85
|
+
try {
|
|
86
|
+
const encrypted = MeebonCrypto.decryptData(req.body.data, privateKey);
|
|
87
|
+
req.body.data = JSON.parse(encrypted);
|
|
88
|
+
} catch (error) {
|
|
89
|
+
next(new Error(error?.message || "Encryption failed."));
|
|
93
90
|
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
91
|
+
}
|
|
92
|
+
const originalSend = res.send.bind(res);
|
|
93
|
+
res.send = (body) => {
|
|
94
|
+
let encryptData = body;
|
|
95
|
+
try {
|
|
96
|
+
if (encryptData?.data) {
|
|
97
|
+
const decrypted = MeebonCrypto.encryptData(encryptData.data, publicKey);
|
|
98
|
+
try {
|
|
99
|
+
encryptData.data = JSON.parse(decrypted);
|
|
100
|
+
} catch {
|
|
101
|
+
encryptData.data = decrypted;
|
|
106
102
|
}
|
|
107
|
-
} catch (error) {
|
|
108
|
-
next(new Error(error?.message || "Decryption failed."));
|
|
109
103
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
104
|
+
} catch (error) {
|
|
105
|
+
next(new Error(error?.message || "Decryption failed."));
|
|
106
|
+
}
|
|
107
|
+
return originalSend(encryptData);
|
|
108
|
+
};
|
|
113
109
|
next();
|
|
114
110
|
};
|
|
115
111
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meebon/meebon-crypto",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.22",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "kajalanS <103587022+kajalanS@users.noreply.github.com>",
|
|
6
6
|
"homepage": "https://github.com/KsoftmHub/meebon-crypto?tab=readme-ov-file#getting-started",
|
package/types/global.d.ts
CHANGED