encrypt-rsa 1.0.11 → 1.2.1

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/CHANGELOG.md CHANGED
@@ -1,3 +1,35 @@
1
+ #### 1.2.1 (2022-02-11)
2
+
3
+ ##### Documentation Changes
4
+
5
+ * update docs ([846687b4](https://github.com/miladezzat/encrypt-rsa/commit/846687b4226bad946b2c0a20636ebec433c9005a))
6
+
7
+ ##### New Features
8
+
9
+ * add encrypt-rsa.js.org ([3f6b0b4e](https://github.com/miladezzat/encrypt-rsa/commit/3f6b0b4e1fbc8082b9416f3dadd3be277a6e5c3f))
10
+
11
+ ### 1.2.0 (2022-02-09)
12
+
13
+ ##### Documentation Changes
14
+
15
+ * set docs ([6f1fa5e3](https://github.com/miladezzat/encrypt-rsa/commit/6f1fa5e38e7d1ef0576a8e49501766f540715477))
16
+
17
+ ### 1.1.0 (2021-07-21)
18
+
19
+ ##### Documentation Changes
20
+
21
+ * ✏️ update docs for creating keys ([cebb2758](https://github.com/miladezzat/encrypt-rsa/commit/cebb2758ac55478d46f0ae6228a10f8f1f78b8c3))
22
+
23
+ ##### New Features
24
+
25
+ * 🎸 add create public and private keys ([74c51131](https://github.com/miladezzat/encrypt-rsa/commit/74c51131a858ad28cdda605b479b6bd21297e730))
26
+
27
+ #### 1.0.12 (2021-07-20)
28
+
29
+ ##### Chores
30
+
31
+ * 🤖 update keywords ([b435e3ba](https://github.com/miladezzat/encrypt-rsa/commit/b435e3ba757a80dd66b95ed8a8a668952b66558e))
32
+
1
33
  #### 1.0.11 (2021-07-20)
2
34
 
3
35
  ##### Bug Fixes
package/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
  # Encrypt By RSA Algorithm
3
3
 
4
4
  [![npm version](https://badge.fury.io/js/encrypt-rsa.svg)](https://badge.fury.io/js/encrypt-rsa) 
5
+ ![https://img.shields.io/npm/dm/encrypt-rsa.svg](https://img.shields.io/npm/dm/encrypt-rsa.svg)
5
6
 
6
7
  > RSA is a public-key cryptosystem that is widely used for secure data transmission. It is also one of the oldest. The acronym RSA comes from the surnames of Ron Rivest, Adi Shamir and Leonard Adleman, who publicly described the algorithm in 1977. [Wikipedia](https://en.wikipedia.org/wiki/RSA_(cryptosystem))
7
8
 
@@ -32,8 +33,19 @@ import NodeRSA from 'encrypt-rsa';
32
33
 
33
34
  const NodeRSA = require('encrypt-rsa').default;
34
35
 
36
+ const fs = require('fs'); // Or import * as fs from 'fs';
37
+
35
38
  const nodeRSA = new NodeRSA();
36
39
 
40
+ // create public and private keys
41
+
42
+ const { privateKey, publicKey } = nodeRSA.createPrivateAndPublicKeys()
43
+
44
+ // to save your keys
45
+ fs.writeFileSync('./private-key', privateKey);
46
+ fs.writeFileSync('./public-key', publicKey);
47
+
48
+
37
49
  // you must have 'public-key' file the key you want to encrypt by it
38
50
 
39
51
  const encryptedText = nodeRSA.encryptStringWithRsaPublicKey({
@@ -59,4 +71,4 @@ console.log({ decryptedText });
59
71
 
60
72
  ```
61
73
  for more information about RSA:
62
- [https://simple.wikipedia.org/wiki/RSA_algorithm](https://simple.wikipedia.org/wiki/RSA_algorithm)
74
+ [https://simple.wikipedia.org/wiki/RSA_algorithm](https://simple.wikipedia.org/wiki/RSA_algorithm)
package/build/index.d.ts CHANGED
@@ -1,16 +1,14 @@
1
- declare type parameters = {
2
- text: string;
3
- keyPath: string;
4
- };
1
+ import { parametersOfEncryptAndDecrypt, returnCreateKeys } from './utils/types';
5
2
  declare class NodeRSA {
6
3
  private publicKeyPath;
7
4
  private privateKeyPath;
5
+ private modulusLength;
8
6
  /**
9
7
  *
10
8
  * @param publicKeyPath this should be absolute path
11
9
  * @param privateKeyPath this should be absolute path
12
10
  */
13
- constructor(publicKeyPath?: string, privateKeyPath?: string);
11
+ constructor(publicKeyPath?: string, privateKeyPath?: string, modulusLength?: number);
14
12
  /**
15
13
  *
16
14
  * @param {Object} args
@@ -19,7 +17,7 @@ declare class NodeRSA {
19
17
  *
20
18
  * @returns {String}
21
19
  */
22
- encryptStringWithRsaPublicKey(args: parameters): string;
20
+ encryptStringWithRsaPublicKey(args: parametersOfEncryptAndDecrypt): string;
23
21
  /**
24
22
  *
25
23
  * @param {Object} args
@@ -28,6 +26,7 @@ declare class NodeRSA {
28
26
  *
29
27
  * @returns {String}
30
28
  */
31
- decryptStringWithRsaPrivateKey(args: parameters): string;
29
+ decryptStringWithRsaPrivateKey(args: parametersOfEncryptAndDecrypt): string;
30
+ createPrivateAndPublicKeys(modulusLength?: number): returnCreateKeys;
32
31
  }
33
32
  export default NodeRSA;
package/build/index.js CHANGED
@@ -3,17 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var crypto_1 = require("crypto");
4
4
  var fs_1 = require("fs");
5
5
  var path_1 = require("path");
6
+ var generateKeyPairSync = require('crypto').generateKeyPairSync;
6
7
  var NodeRSA = /** @class */ (function () {
7
8
  /**
8
9
  *
9
10
  * @param publicKeyPath this should be absolute path
10
11
  * @param privateKeyPath this should be absolute path
11
12
  */
12
- function NodeRSA(publicKeyPath, privateKeyPath) {
13
+ function NodeRSA(publicKeyPath, privateKeyPath, modulusLength) {
13
14
  if (publicKeyPath === void 0) { publicKeyPath = ''; }
14
15
  if (privateKeyPath === void 0) { privateKeyPath = ''; }
15
16
  this.publicKeyPath = publicKeyPath;
16
17
  this.privateKeyPath = privateKeyPath;
18
+ this.modulusLength = modulusLength || 2048;
17
19
  }
18
20
  /**
19
21
  *
@@ -47,6 +49,21 @@ var NodeRSA = /** @class */ (function () {
47
49
  var decrypted = crypto_1.privateDecrypt(privateKey, buffer);
48
50
  return decrypted.toString('utf8');
49
51
  };
52
+ NodeRSA.prototype.createPrivateAndPublicKeys = function (modulusLength) {
53
+ if (modulusLength === void 0) { modulusLength = this.modulusLength; }
54
+ var _a = generateKeyPairSync('rsa', {
55
+ modulusLength: modulusLength,
56
+ publicKeyEncoding: {
57
+ type: 'spki',
58
+ format: 'pem',
59
+ },
60
+ privateKeyEncoding: {
61
+ type: 'pkcs8',
62
+ format: 'pem',
63
+ },
64
+ }), privateKey = _a.privateKey, publicKey = _a.publicKey;
65
+ return { privateKey: privateKey, publicKey: publicKey };
66
+ };
50
67
  return NodeRSA;
51
68
  }());
52
69
  exports.default = NodeRSA;
@@ -0,0 +1,8 @@
1
+ export declare type returnCreateKeys = {
2
+ privateKey: string;
3
+ publicKey: string;
4
+ };
5
+ export declare type parametersOfEncryptAndDecrypt = {
6
+ text: string;
7
+ keyPath: string;
8
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "encrypt-rsa",
3
- "version": "1.0.11",
3
+ "version": "1.2.1",
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",
@@ -14,7 +14,8 @@
14
14
  "depcheck": "./node_modules/.bin/depcheck",
15
15
  "prepare": "husky install",
16
16
  "build": "tsc",
17
- "git-cz": "./node_modules/.bin/git-cz",
17
+ "commit": "./node_modules/.bin/git-cz",
18
+ "docs:serve": "docsify serve docs",
18
19
  "_postinstall": "husky install",
19
20
  "prepublishOnly": "pinst --disable",
20
21
  "postpublish": "pinst --enable",
@@ -32,6 +33,7 @@
32
33
  "@typescript-eslint/parser": "^4.28.3",
33
34
  "chai": "^4.3.4",
34
35
  "commitizen": "^4.2.4",
36
+ "docsify-cli": "^4.4.3",
35
37
  "cz-conventional-changelog": "^3.3.0",
36
38
  "depcheck": "^1.4.2",
37
39
  "eslint": "^7.31.0",
@@ -55,7 +57,11 @@
55
57
  "node-rsa",
56
58
  "encrypt",
57
59
  "encrypt by public key",
58
- "decrypt by private key"
60
+ "decrypt by private key",
61
+ "rsa encryption",
62
+ "node-rsa typescript",
63
+ "Crypto-js RSA",
64
+ "Javascript RSA encryption"
59
65
  ],
60
66
  "author": "Milad E. Fahmy <miladezzat.f@gmail.com> (https://milad-ezzat.vercel.app)",
61
67
  "config": {
@@ -74,5 +80,5 @@
74
80
  "bugs": {
75
81
  "url": "https://github.com/miladezzat/encrypt-rsa/issues"
76
82
  },
77
- "homepage": "https://milad-ezzat.vercel.app"
83
+ "homepage": "https://miladezzat.github.io/encrypt-rsa/"
78
84
  }