encrypt-rsa 2.0.1 → 2.1.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/README.md CHANGED
@@ -4,11 +4,15 @@
4
4
  [![npm version](https://badge.fury.io/js/encrypt-rsa.svg)](https://badge.fury.io/js/encrypt-rsa) 
5
5
  ![https://img.shields.io/npm/dm/encrypt-rsa.svg](https://img.shields.io/npm/dm/encrypt-rsa.svg)
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
+ This package works fine with web browsers and servers
8
+
9
+ > 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))
8
10
 
9
11
  RSA algorithm is asymmetric cryptography algorithm. Asymmetric actually means that it works on two different keys i.e. Public Key and Private Key. As the name describes that the Public Key is given to everyone and Private key is kept private.
10
12
 
11
- ## For more explanation about RSA Algorithm visit [RSA algorithm](https://milad-ezzat.vercel.app/blog/encrypt-by-rsa-algorithm)
13
+ ### For more explanation about RSA Algorithm visit
14
+
15
+ - [Rsa Algorithm](https://milad-ezzat.vercel.app/blog/encrypt-by-rsa-algorithm)
12
16
 
13
17
  1. [Installation](#installation)
14
18
  2. [Usage](#usage)
@@ -17,52 +21,55 @@ RSA algorithm is asymmetric cryptography algorithm. Asymmetric actually means th
17
21
 
18
22
  ```bash
19
23
  npm i encrypt-rsa
20
-
21
24
  // OR
22
-
23
25
  yarn add encrypt-rsa
24
26
  ```
25
27
 
26
-
27
28
  ## Usage
28
29
 
29
30
  ```js
30
- import NodeRSA from 'encrypt-rsa';
31
+ import EncryptRsa from 'encrypt-rsa';
31
32
 
32
33
  //OR
33
34
 
34
- const NodeRSA = require('encrypt-rsa').default;
35
+ const EncryptRsa = require('encrypt-rsa').default;
35
36
 
36
- const fs = require('fs'); // Or import * as fs from 'fs';
37
-
38
- const nodeRSA = new NodeRSA();
39
-
40
- // create public and private keys
37
+ // create instance
38
+ const encryptRsa = new EncryptRsa();
39
+ ```
41
40
 
42
- const { privateKey, publicKey } = nodeRSA.createPrivateAndPublicKeys()
41
+ ### Create Private and Public keys
43
42
 
43
+ ```js
44
+ const { privateKey, publicKey } = nodeRSA.createPrivateAndPublicKeys();
45
+ ```
44
46
 
45
- // you must have 'public-key' file the key you want to encrypt by it
47
+ ### Encrypt Text
46
48
 
47
- const encryptedText = nodeRSA.encryptStringWithRsaPublicKey({
48
- text: 'hello',
49
- publicKey: public
49
+ ```js
50
+ const encryptedText = encryptRsa.encryptStringWithRsaPublicKey({
51
+ text: 'hello world',
52
+ publicKey,
50
53
  });
54
+ console.log(encryptedText);
51
55
 
52
- console.log({ encryptedText });
53
-
54
- //result: {
55
- // encryptedText: 'QAoJBAj7ZqYR9Qb9vFGfpjBVY7BP0MtlPywyxMSodA7WmOmOn0glOlrLxUqjJrmaKsqxdJxZadEMAM8+6gLNhwcLtbFPRLQEUTSHk2NNhehsPOESoNjwbXOj5Y+zBCSkjVuW6MRkdaTZeGXi0sii1OqvIQGmOaOR2xzEdDj2eD8='
56
- // }
56
+ // QMPLJN3KzvXxkll18wax+KxqC0UqiHrwMxYGNUmJWMi98diapGOL/WzliPP3bTrHu7yWU1DnaB3f71w6JBYP+wG98fWLaz8+rwemerVja8B0FJVUphjBUmoDhX52JSoLFI0YVHtihXtoRk1pVaRFWm8FmZPZAcCKL7a0YDI1wABGvcSbLhaacmgX6zR6fzyltWVCrXn0NcVGox7WK7x4sCtywNhZx2XuUVSztr7QYcV2OQe8aDTUd7NXtaBVkj9RUYUR2QvhIpETksx14WD4ytohM68RUIJLRmU3y761mxcF+7Pjw/Utcirqu2Ohg0K18xGqlaE6fdifh0vIlfH+kA==
57
+ ```
57
58
 
58
- // you must have 'private-key' file the key you want to decrypt by it
59
+ ### Decrypt Encrypted Text
59
60
 
61
+ ```js
60
62
  const decryptedText = nodeRSA.decryptStringWithRsaPrivateKey({
61
63
  text: encryptedText,
62
- privateKey: private
64
+ privateKey
63
65
  });
66
+ console.log(decryptedText);
67
+ // hello world
68
+ ```
64
69
 
65
- console.log({ decryptedText });
66
- // result: { decryptedText: 'hello' }
70
+ ## Rsa Algorithm:
71
+ - [RSA Algorithm](https://simple.wikipedia.org/wiki/RSA_algorithm)
67
72
 
68
- ```
73
+
74
+ ### Contributions
75
+ feel free to open an [issue](https://github.com/miladezzat/encrypt-rsa/issues) and make a [pull request](https://github.com/miladezzat/encrypt-rsa/pulls)
package/build/index.js CHANGED
@@ -24,9 +24,9 @@ var NodeRSA = /** @class */ (function () {
24
24
  */
25
25
  NodeRSA.prototype.encryptStringWithRsaPublicKey = function (args) {
26
26
  var text = args.text, _a = args.publicKey, publicKey = _a === void 0 ? this.publicKey : _a;
27
- var publicKeyDecoded = helpers_1.decode(this.convertKetToBase64(publicKey));
27
+ var publicKeyDecoded = (0, helpers_1.decode)(this.convertKetToBase64(publicKey));
28
28
  var buffer = Buffer.from(text);
29
- var encrypted = crypto_1.publicEncrypt(publicKeyDecoded, buffer);
29
+ var encrypted = (0, crypto_1.publicEncrypt)(publicKeyDecoded, buffer);
30
30
  return encrypted.toString('base64');
31
31
  };
32
32
  /**
@@ -39,14 +39,14 @@ var NodeRSA = /** @class */ (function () {
39
39
  */
40
40
  NodeRSA.prototype.decryptStringWithRsaPrivateKey = function (args) {
41
41
  var text = args.text, _a = args.privateKey, privateKey = _a === void 0 ? this.privateKey : _a;
42
- var privateKeyDecoded = helpers_1.decode(this.convertKetToBase64(privateKey));
42
+ var privateKeyDecoded = (0, helpers_1.decode)(this.convertKetToBase64(privateKey));
43
43
  var buffer = Buffer.from(text, 'base64');
44
- var decrypted = crypto_1.privateDecrypt(privateKeyDecoded, buffer);
44
+ var decrypted = (0, crypto_1.privateDecrypt)(privateKeyDecoded, buffer);
45
45
  return decrypted.toString('utf8');
46
46
  };
47
47
  NodeRSA.prototype.createPrivateAndPublicKeys = function (modulusLength) {
48
48
  if (modulusLength === void 0) { modulusLength = this.modulusLength; }
49
- var _a = crypto_1.generateKeyPairSync('rsa', {
49
+ var _a = (0, crypto_1.generateKeyPairSync)('rsa', {
50
50
  modulusLength: modulusLength,
51
51
  publicKeyEncoding: {
52
52
  type: 'spki',
@@ -60,7 +60,7 @@ var NodeRSA = /** @class */ (function () {
60
60
  return { privateKey: privateKey, publicKey: publicKey };
61
61
  };
62
62
  NodeRSA.prototype.convertKetToBase64 = function (key) {
63
- return helpers_1.encode(key.replace(/^ +/gm, '') || this.keyBase64);
63
+ return (0, helpers_1.encode)(key.replace(/^ +/gm, '') || this.keyBase64);
64
64
  };
65
65
  return NodeRSA;
66
66
  }());
package/package.json CHANGED
@@ -1,49 +1,52 @@
1
1
  {
2
2
  "name": "encrypt-rsa",
3
- "version": "2.0.1",
4
- "description": "this is a little module use to encrypt and decrypt strings with RSA keys (public and private keys)",
3
+ "version": "2.1.1",
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": "16.x",
12
+ "npm": "8.x"
13
+ },
10
14
  "types": "./build/index.d.ts",
11
15
  "source": "./src/index.ts",
12
16
  "scripts": {
13
- "test": "./node_modules/.bin/mocha -r ts-node/register tests/**/*.spec.ts",
14
- "depcheck": "./node_modules/.bin/depcheck",
17
+ "test": "mocha -r ts-node/register tests/**/*.spec.ts",
18
+ "depcheck": "npm-check",
15
19
  "prepare": "husky install",
16
20
  "build": "tsc",
17
- "commit": "./node_modules/.bin/git-cz",
21
+ "commit": "git-cz",
18
22
  "docs:serve": "docsify serve docs",
19
23
  "_postinstall": "husky install",
20
24
  "prepublishOnly": "pinst --disable",
21
25
  "postpublish": "pinst --enable",
22
- "husky": "./node_modules/.bin/husky",
23
- "lint": "./node_modules/.bin/eslint",
26
+ "husky": "husky",
27
+ "lint": "eslint",
24
28
  "release:major": "changelog -M && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version major && git push origin && git push origin --tags",
25
29
  "release:minor": "changelog -m && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version minor && git push origin && git push origin --tags",
26
30
  "release:patch": "changelog -p && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version patch && git push origin && git push origin --tags"
27
31
  },
28
32
  "devDependencies": {
29
33
  "@types/chai": "^4.2.21",
30
- "@types/mocha": "^8.2.3",
31
- "@types/node": "^16.3.3",
32
- "@typescript-eslint/eslint-plugin": "^4.28.3",
33
- "@typescript-eslint/parser": "^4.28.3",
34
+ "@types/mocha": "^9.1.1",
35
+ "@types/node": "^17.0.38",
36
+ "@typescript-eslint/eslint-plugin": "^5.27.0",
37
+ "@typescript-eslint/parser": "^5.27.0",
34
38
  "chai": "^4.3.4",
35
39
  "commitizen": "^4.2.4",
36
- "docsify-cli": "^4.4.3",
37
40
  "cz-conventional-changelog": "^3.3.0",
38
- "depcheck": "^1.4.2",
39
- "eslint": "^7.31.0",
40
- "eslint-config-airbnb-base": "^14.2.1",
41
+ "docsify-cli": "^4.4.3",
42
+ "eslint": "^8.16.0",
43
+ "eslint-config-airbnb-base": "^15.0.0",
41
44
  "eslint-plugin-import": "^2.23.4",
42
45
  "generate-changelog": "^1.8.0",
43
46
  "git-cz": "^4.7.6",
44
- "husky": "^7.0.1",
45
- "mocha": "^9.0.2",
46
- "pinst": "^2.1.6",
47
+ "husky": "^8.0.1",
48
+ "mocha": "^10.0.0",
49
+ "pinst": "^3.0.0",
47
50
  "ts-node": "^10.1.0",
48
51
  "typescript": "^4.3.5"
49
52
  },
@@ -80,5 +83,8 @@
80
83
  "bugs": {
81
84
  "url": "https://github.com/miladezzat/encrypt-rsa/issues"
82
85
  },
83
- "homepage": "https://encrypt-rsa.js.org"
86
+ "homepage": "https://encrypt-rsa.js.org",
87
+ "dependencies": {
88
+ "npm-check": "^5.9.2"
89
+ }
84
90
  }
package/CHANGELOG.md DELETED
@@ -1,95 +0,0 @@
1
- #### 2.0.1 (2022-03-23)
2
-
3
- ##### Documentation Changes
4
-
5
- * update docs ([c06781e3](https://github.com/miladezzat/encrypt-rsa/commit/c06781e34ec15219f12c1be880005b0ab6696d4a))
6
-
7
- ## 2.0.0 (2022-03-23)
8
-
9
- ##### Documentation Changes
10
-
11
- * update docs ([e4e3f254](https://github.com/miladezzat/encrypt-rsa/commit/e4e3f254a4819922138f1e1763415207dc1591c6))
12
- * update docs ([de0f8024](https://github.com/miladezzat/encrypt-rsa/commit/de0f8024aad85c591273f93b50952cd72e230693))
13
-
14
- ##### New Features
15
-
16
- * make methods to take public and private keys as strings ([d47af0f5](https://github.com/miladezzat/encrypt-rsa/commit/d47af0f5c39d49cfb1589b0e236cc7c995bfb395))
17
- * add new helper methods to decode and encode keys to base64 ([d3cba4c0](https://github.com/miladezzat/encrypt-rsa/commit/d3cba4c0f36d42e615f22c4ed4b828ed151faecb))
18
- * update the docs ([4e470c6f](https://github.com/miladezzat/encrypt-rsa/commit/4e470c6feabfc828172bc484285239a24df064a4))
19
-
20
- ##### Tests
21
-
22
- * add tests ([373d6c12](https://github.com/miladezzat/encrypt-rsa/commit/373d6c125184bd2e1394091def64280a5392413e))
23
-
24
- #### 1.2.1 (2022-02-11)
25
-
26
- ##### Documentation Changes
27
-
28
- * update docs ([846687b4](https://github.com/miladezzat/encrypt-rsa/commit/846687b4226bad946b2c0a20636ebec433c9005a))
29
-
30
- ##### New Features
31
-
32
- * add encrypt-rsa.js.org ([3f6b0b4e](https://github.com/miladezzat/encrypt-rsa/commit/3f6b0b4e1fbc8082b9416f3dadd3be277a6e5c3f))
33
-
34
- ### 1.2.0 (2022-02-09)
35
-
36
- ##### Documentation Changes
37
-
38
- * set docs ([6f1fa5e3](https://github.com/miladezzat/encrypt-rsa/commit/6f1fa5e38e7d1ef0576a8e49501766f540715477))
39
-
40
- ### 1.1.0 (2021-07-21)
41
-
42
- ##### Documentation Changes
43
-
44
- * ✏️ update docs for creating keys ([cebb2758](https://github.com/miladezzat/encrypt-rsa/commit/cebb2758ac55478d46f0ae6228a10f8f1f78b8c3))
45
-
46
- ##### New Features
47
-
48
- * 🎸 add create public and private keys ([74c51131](https://github.com/miladezzat/encrypt-rsa/commit/74c51131a858ad28cdda605b479b6bd21297e730))
49
-
50
- #### 1.0.12 (2021-07-20)
51
-
52
- ##### Chores
53
-
54
- * 🤖 update keywords ([b435e3ba](https://github.com/miladezzat/encrypt-rsa/commit/b435e3ba757a80dd66b95ed8a8a668952b66558e))
55
-
56
- #### 1.0.11 (2021-07-20)
57
-
58
- ##### Bug Fixes
59
-
60
- * 🐛 solve docs ([8a08c44e](https://github.com/miladezzat/encrypt-rsa/commit/8a08c44e767d5dcd242b5a5806602468cb663ec1))
61
-
62
- #### 1.0.10 (2021-07-20)
63
-
64
- ##### Documentation Changes
65
-
66
- * ✏️ update readme ([e29f1805](https://github.com/miladezzat/encrypt-rsa/commit/e29f180513d8f79daaad9fee7e0a532e2e94f076))
67
-
68
- #### 1.0.9 (2021-07-19)
69
-
70
- #### 1.0.8 (2021-07-19)
71
-
72
- #### 1.0.8 (2021-07-19)
73
-
74
- #### 1.0.5 (2021-07-19)
75
-
76
- #### 1.0.4 (2021-07-19)
77
-
78
- #### 1.0.4 (2021-07-19)
79
-
80
- #### 1.0.3 (2021-07-19)
81
-
82
- #### 1.0.2 (2021-07-19)
83
-
84
- #### 1.0.1 (2021-07-19)
85
-
86
- ##### Other Changes
87
-
88
- * miladezzat/rsa-node ([5f3c40de](https://github.com/miladezzat/encrypt-rsa/commit/5f3c40deb5cf9424bee39bfae4620866e828fcf8))
89
-
90
- ## 1.0.0 (2021-07-18)
91
-
92
- ##### Other Changes
93
-
94
- * miladezzat/rsa-node (5f3c40de)
95
-