encrypt-rsa 2.1.4 → 2.2.0

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
@@ -47,21 +47,19 @@ const { privateKey, publicKey } = nodeRSA.createPrivateAndPublicKeys();
47
47
  ### Encrypt Text
48
48
 
49
49
  ```js
50
- const encryptedText = encryptRsa.encryptStringWithRsaPublicKey({
50
+ const encryptedText = encryptRsa.encrypt({
51
51
  text: 'hello world',
52
- publicKey,
52
+ privateKey,
53
53
  });
54
54
  console.log(encryptedText);
55
-
56
- // QMPLJN3KzvXxkll18wax+KxqC0UqiHrwMxYGNUmJWMi98diapGOL/WzliPP3bTrHu7yWU1DnaB3f71w6JBYP+wG98fWLaz8+rwemerVja8B0FJVUphjBUmoDhX52JSoLFI0YVHtihXtoRk1pVaRFWm8FmZPZAcCKL7a0YDI1wABGvcSbLhaacmgX6zR6fzyltWVCrXn0NcVGox7WK7x4sCtywNhZx2XuUVSztr7QYcV2OQe8aDTUd7NXtaBVkj9RUYUR2QvhIpETksx14WD4ytohM68RUIJLRmU3y761mxcF+7Pjw/Utcirqu2Ohg0K18xGqlaE6fdifh0vIlfH+kA==
57
55
  ```
58
56
 
59
57
  ### Decrypt Encrypted Text
60
58
 
61
59
  ```js
62
- const decryptedText = nodeRSA.decryptStringWithRsaPrivateKey({
60
+ const decryptedText = nodeRSA.decrypt({
63
61
  text: encryptedText,
64
- privateKey
62
+ publicKey
65
63
  });
66
64
  console.log(decryptedText);
67
65
  // hello world
package/build/index.d.ts CHANGED
@@ -5,29 +5,47 @@ declare class NodeRSA {
5
5
  private modulusLength;
6
6
  private keyBase64;
7
7
  /**
8
- *
9
- * @param publicKey
10
- * @param privateKey
11
- */
8
+ *
9
+ * @param publicKey
10
+ * @param privateKey
11
+ */
12
12
  constructor(publicKey?: string, privateKey?: string, modulusLength?: number);
13
13
  /**
14
- *
15
- * @param {Object} args
16
- * @param {String} args.publicKey
17
- * @param {String} args.text the text that you need to encrypt
18
- *
19
- * @returns {String}
20
- */
14
+ *
15
+ * @param {Object} args
16
+ * @param {String} args.privateKey
17
+ * @param {String} args.text the text that you need to encrypt
18
+ * @deprecated
19
+ * @returns {String}
20
+ */
21
21
  encryptStringWithRsaPublicKey(args: parametersOfEncrypt): string;
22
+ /**
23
+ *
24
+ * @param {Object} args
25
+ * @param {String} args.privateKey
26
+ * @param {String} args.text the text that you need to decrypt
27
+ * @deprecated
28
+ * @returns {String}
29
+ */
30
+ decryptStringWithRsaPrivateKey(args: parametersOfDecrypt): string;
22
31
  /**
23
32
  *
24
33
  * @param {Object} args
25
34
  * @param {String} args.privateKey
26
- * @param {String} args.text the text that you need to decrypt
35
+ * @param {String} args.text the text that you need to encrypt
27
36
  *
28
37
  * @returns {String}
29
38
  */
30
- decryptStringWithRsaPrivateKey(args: parametersOfDecrypt): string;
39
+ encrypt(args: parametersOfEncrypt): string;
40
+ /**
41
+ *
42
+ * @param {Object} args
43
+ * @param {String} args.privateKey
44
+ * @param {String} args.text the text that you need to decrypt
45
+ *
46
+ * @returns {String}
47
+ */
48
+ decrypt(args: parametersOfDecrypt): string;
31
49
  createPrivateAndPublicKeys(modulusLength?: number): returnCreateKeys;
32
50
  private convertKetToBase64;
33
51
  }
package/build/index.js CHANGED
@@ -27,10 +27,10 @@ var crypto = __importStar(require("crypto"));
27
27
  var helpers_1 = require("./utils/helpers");
28
28
  var NodeRSA = /** @class */ (function () {
29
29
  /**
30
- *
31
- * @param publicKey
32
- * @param privateKey
33
- */
30
+ *
31
+ * @param publicKey
32
+ * @param privateKey
33
+ */
34
34
  function NodeRSA(publicKey, privateKey, modulusLength) {
35
35
  this.publicKey = publicKey;
36
36
  this.privateKey = privateKey;
@@ -38,33 +38,63 @@ var NodeRSA = /** @class */ (function () {
38
38
  this.keyBase64 = '';
39
39
  }
40
40
  /**
41
- *
42
- * @param {Object} args
43
- * @param {String} args.publicKey
44
- * @param {String} args.text the text that you need to encrypt
45
- *
46
- * @returns {String}
47
- */
41
+ *
42
+ * @param {Object} args
43
+ * @param {String} args.privateKey
44
+ * @param {String} args.text the text that you need to encrypt
45
+ * @deprecated
46
+ * @returns {String}
47
+ */
48
48
  NodeRSA.prototype.encryptStringWithRsaPublicKey = function (args) {
49
- var text = args.text, _a = args.publicKey, publicKey = _a === void 0 ? this.publicKey : _a;
50
- var publicKeyDecoded = (0, helpers_1.decode)(this.convertKetToBase64(publicKey));
49
+ var text = args.text, _a = args.privateKey, privateKey = _a === void 0 ? this.privateKey : _a;
50
+ var publicKeyDecoded = (0, helpers_1.decode)(this.convertKetToBase64(privateKey));
51
51
  var buffer = Buffer.from(text);
52
52
  var encrypted = crypto === null || crypto === void 0 ? void 0 : crypto.publicEncrypt(publicKeyDecoded, buffer);
53
53
  return encrypted.toString('base64');
54
54
  };
55
+ /**
56
+ *
57
+ * @param {Object} args
58
+ * @param {String} args.privateKey
59
+ * @param {String} args.text the text that you need to decrypt
60
+ * @deprecated
61
+ * @returns {String}
62
+ */
63
+ NodeRSA.prototype.decryptStringWithRsaPrivateKey = function (args) {
64
+ var text = args.text, _a = args.publicKey, publicKey = _a === void 0 ? this.publicKey : _a;
65
+ var publicKeyDecoded = (0, helpers_1.decode)(this.convertKetToBase64(publicKey));
66
+ var buffer = Buffer.from(text, 'base64');
67
+ var decrypted = crypto === null || crypto === void 0 ? void 0 : crypto.privateDecrypt(publicKeyDecoded, buffer);
68
+ return decrypted.toString('utf8');
69
+ };
55
70
  /**
56
71
  *
57
72
  * @param {Object} args
58
73
  * @param {String} args.privateKey
59
- * @param {String} args.text the text that you need to decrypt
74
+ * @param {String} args.text the text that you need to encrypt
60
75
  *
61
76
  * @returns {String}
62
77
  */
63
- NodeRSA.prototype.decryptStringWithRsaPrivateKey = function (args) {
78
+ NodeRSA.prototype.encrypt = function (args) {
64
79
  var text = args.text, _a = args.privateKey, privateKey = _a === void 0 ? this.privateKey : _a;
65
- var privateKeyDecoded = (0, helpers_1.decode)(this.convertKetToBase64(privateKey));
80
+ var publicKeyDecoded = (0, helpers_1.decode)(this.convertKetToBase64(privateKey));
81
+ var buffer = Buffer.from(text);
82
+ var encrypted = crypto === null || crypto === void 0 ? void 0 : crypto.publicEncrypt(publicKeyDecoded, buffer);
83
+ return encrypted.toString('base64');
84
+ };
85
+ /**
86
+ *
87
+ * @param {Object} args
88
+ * @param {String} args.privateKey
89
+ * @param {String} args.text the text that you need to decrypt
90
+ *
91
+ * @returns {String}
92
+ */
93
+ NodeRSA.prototype.decrypt = function (args) {
94
+ var text = args.text, _a = args.publicKey, publicKey = _a === void 0 ? this.publicKey : _a;
95
+ var publicKeyDecoded = (0, helpers_1.decode)(this.convertKetToBase64(publicKey));
66
96
  var buffer = Buffer.from(text, 'base64');
67
- var decrypted = crypto === null || crypto === void 0 ? void 0 : crypto.privateDecrypt(privateKeyDecoded, buffer);
97
+ var decrypted = crypto === null || crypto === void 0 ? void 0 : crypto.privateDecrypt(publicKeyDecoded, buffer);
68
98
  return decrypted.toString('utf8');
69
99
  };
70
100
  NodeRSA.prototype.createPrivateAndPublicKeys = function (modulusLength) {
@@ -81,7 +111,7 @@ var NodeRSA = /** @class */ (function () {
81
111
  format: 'pem',
82
112
  },
83
113
  }), privateKey = _a.privateKey, publicKey = _a.publicKey;
84
- return { privateKey: privateKey, publicKey: publicKey };
114
+ return { publicKey: privateKey, privateKey: publicKey };
85
115
  }
86
116
  return { privateKey: '', publicKey: '' };
87
117
  };
@@ -4,9 +4,9 @@ export declare type returnCreateKeys = {
4
4
  };
5
5
  export declare type parametersOfEncrypt = {
6
6
  text: string;
7
- publicKey?: string;
7
+ privateKey?: string;
8
8
  };
9
9
  export declare type parametersOfDecrypt = {
10
10
  text: string;
11
- privateKey?: string;
11
+ publicKey?: string;
12
12
  };
package/package.json CHANGED
@@ -1,16 +1,12 @@
1
1
  {
2
2
  "name": "encrypt-rsa",
3
- "version": "2.1.4",
3
+ "version": "2.2.0",
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",
7
7
  "files": [
8
8
  "build/**/*"
9
9
  ],
10
- "engines": {
11
- "node": "18.x",
12
- "npm": "8.x"
13
- },
14
10
  "types": "./build/index.d.ts",
15
11
  "source": "./src/index.ts",
16
12
  "scripts": {
@@ -26,9 +22,7 @@
26
22
  "prepublish": "npm run build",
27
23
  "husky": "husky",
28
24
  "lint": "eslint",
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",
30
- "release:minor": "changelog -m && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version minor && git push origin && git push origin --tags",
31
- "release:patch": "changelog -p && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version patch && git push origin && git push origin --tags"
25
+ "release": "standard-version && git push --follow-tags"
32
26
  },
33
27
  "devDependencies": {
34
28
  "@types/chai": "^4.2.21",
@@ -49,6 +43,7 @@
49
43
  "mocha": "^10.0.0",
50
44
  "pinst": "^3.0.0",
51
45
  "ts-node": "^10.1.0",
46
+ "standard-version": "^9.5.0",
52
47
  "typescript": "^4.3.5"
53
48
  },
54
49
  "keywords": [