encrypt-rsa 2.1.2 → 2.1.4
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.
- package/build/index.js +41 -15
- package/package.json +3 -3
package/build/index.js
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var
|
|
26
|
+
var crypto = __importStar(require("crypto"));
|
|
4
27
|
var helpers_1 = require("./utils/helpers");
|
|
5
28
|
var NodeRSA = /** @class */ (function () {
|
|
6
29
|
/**
|
|
@@ -26,7 +49,7 @@ var NodeRSA = /** @class */ (function () {
|
|
|
26
49
|
var text = args.text, _a = args.publicKey, publicKey = _a === void 0 ? this.publicKey : _a;
|
|
27
50
|
var publicKeyDecoded = (0, helpers_1.decode)(this.convertKetToBase64(publicKey));
|
|
28
51
|
var buffer = Buffer.from(text);
|
|
29
|
-
var encrypted =
|
|
52
|
+
var encrypted = crypto === null || crypto === void 0 ? void 0 : crypto.publicEncrypt(publicKeyDecoded, buffer);
|
|
30
53
|
return encrypted.toString('base64');
|
|
31
54
|
};
|
|
32
55
|
/**
|
|
@@ -41,23 +64,26 @@ var NodeRSA = /** @class */ (function () {
|
|
|
41
64
|
var text = args.text, _a = args.privateKey, privateKey = _a === void 0 ? this.privateKey : _a;
|
|
42
65
|
var privateKeyDecoded = (0, helpers_1.decode)(this.convertKetToBase64(privateKey));
|
|
43
66
|
var buffer = Buffer.from(text, 'base64');
|
|
44
|
-
var decrypted =
|
|
67
|
+
var decrypted = crypto === null || crypto === void 0 ? void 0 : crypto.privateDecrypt(privateKeyDecoded, buffer);
|
|
45
68
|
return decrypted.toString('utf8');
|
|
46
69
|
};
|
|
47
70
|
NodeRSA.prototype.createPrivateAndPublicKeys = function (modulusLength) {
|
|
48
71
|
if (modulusLength === void 0) { modulusLength = this.modulusLength; }
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
72
|
+
if (typeof crypto.generateKeyPairSync === 'function') {
|
|
73
|
+
var _a = crypto.generateKeyPairSync('rsa', {
|
|
74
|
+
modulusLength: modulusLength,
|
|
75
|
+
publicKeyEncoding: {
|
|
76
|
+
type: 'spki',
|
|
77
|
+
format: 'pem',
|
|
78
|
+
},
|
|
79
|
+
privateKeyEncoding: {
|
|
80
|
+
type: 'pkcs8',
|
|
81
|
+
format: 'pem',
|
|
82
|
+
},
|
|
83
|
+
}), privateKey = _a.privateKey, publicKey = _a.publicKey;
|
|
84
|
+
return { privateKey: privateKey, publicKey: publicKey };
|
|
85
|
+
}
|
|
86
|
+
return { privateKey: '', publicKey: '' };
|
|
61
87
|
};
|
|
62
88
|
NodeRSA.prototype.convertKetToBase64 = function (key) {
|
|
63
89
|
return (0, helpers_1.encode)(key.replace(/^ +/gm, '') || this.keyBase64);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "encrypt-rsa",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.4",
|
|
4
4
|
"description": "This is a little module use to encrypt and decrypt strings with RSA keys (public and private keys)",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"module": "./build/index.js",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"build/**/*"
|
|
9
9
|
],
|
|
10
10
|
"engines": {
|
|
11
|
-
"node": "
|
|
11
|
+
"node": "18.x",
|
|
12
12
|
"npm": "8.x"
|
|
13
13
|
},
|
|
14
14
|
"types": "./build/index.d.ts",
|
|
@@ -86,6 +86,6 @@
|
|
|
86
86
|
},
|
|
87
87
|
"homepage": "https://encrypt-rsa.js.org",
|
|
88
88
|
"dependencies": {
|
|
89
|
-
"npm-check": "^
|
|
89
|
+
"npm-check": "^6.0.1"
|
|
90
90
|
}
|
|
91
91
|
}
|