encrypt-rsa 2.1.1 → 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/README.md CHANGED
@@ -20,9 +20,9 @@ RSA algorithm is asymmetric cryptography algorithm. Asymmetric actually means th
20
20
  ## Installation
21
21
 
22
22
  ```bash
23
- npm i encrypt-rsa
23
+ npm i encrypt-rsa --only=production
24
24
  // OR
25
- yarn add encrypt-rsa
25
+ yarn add encrypt-rsa --only=production
26
26
  ```
27
27
 
28
28
  ## Usage
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 crypto_1 = require("crypto");
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 = (0, crypto_1.publicEncrypt)(publicKeyDecoded, buffer);
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 = (0, crypto_1.privateDecrypt)(privateKeyDecoded, buffer);
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
- var _a = (0, crypto_1.generateKeyPairSync)('rsa', {
50
- modulusLength: modulusLength,
51
- publicKeyEncoding: {
52
- type: 'spki',
53
- format: 'pem',
54
- },
55
- privateKeyEncoding: {
56
- type: 'pkcs8',
57
- format: 'pem',
58
- },
59
- }), privateKey = _a.privateKey, publicKey = _a.publicKey;
60
- return { privateKey: privateKey, publicKey: publicKey };
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.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": "16.x",
11
+ "node": "18.x",
12
12
  "npm": "8.x"
13
13
  },
14
14
  "types": "./build/index.d.ts",
@@ -23,6 +23,7 @@
23
23
  "_postinstall": "husky install",
24
24
  "prepublishOnly": "pinst --disable",
25
25
  "postpublish": "pinst --enable",
26
+ "prepublish": "npm run build",
26
27
  "husky": "husky",
27
28
  "lint": "eslint",
28
29
  "release:major": "changelog -M && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version major && git push origin && git push origin --tags",
@@ -85,6 +86,6 @@
85
86
  },
86
87
  "homepage": "https://encrypt-rsa.js.org",
87
88
  "dependencies": {
88
- "npm-check": "^5.9.2"
89
+ "npm-check": "^6.0.1"
89
90
  }
90
91
  }