encrypt-rsa 2.0.0 → 2.1.2
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 +36 -35
- package/build/index.js +6 -6
- package/package.json +26 -19
- package/CHANGELOG.md +0 -89
package/README.md
CHANGED
|
@@ -4,11 +4,15 @@
|
|
|
4
4
|
[](https://badge.fury.io/js/encrypt-rsa)
|
|
5
5
|

|
|
6
6
|
|
|
7
|
-
|
|
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
|
|
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)
|
|
@@ -16,59 +20,56 @@ RSA algorithm is asymmetric cryptography algorithm. Asymmetric actually means th
|
|
|
16
20
|
## Installation
|
|
17
21
|
|
|
18
22
|
```bash
|
|
19
|
-
npm i encrypt-rsa
|
|
20
|
-
|
|
23
|
+
npm i encrypt-rsa --only=production
|
|
21
24
|
// OR
|
|
22
|
-
|
|
23
|
-
yarn add encrypt-rsa
|
|
25
|
+
yarn add encrypt-rsa --only=production
|
|
24
26
|
```
|
|
25
27
|
|
|
26
|
-
|
|
27
28
|
## Usage
|
|
28
29
|
|
|
29
30
|
```js
|
|
30
|
-
import
|
|
31
|
+
import EncryptRsa from 'encrypt-rsa';
|
|
31
32
|
|
|
32
33
|
//OR
|
|
33
34
|
|
|
34
|
-
const
|
|
35
|
+
const EncryptRsa = require('encrypt-rsa').default;
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
// create public and private keys
|
|
41
|
-
|
|
42
|
-
const { privateKey, publicKey } = nodeRSA.createPrivateAndPublicKeys()
|
|
37
|
+
// create instance
|
|
38
|
+
const encryptRsa = new EncryptRsa();
|
|
39
|
+
```
|
|
43
40
|
|
|
44
|
-
|
|
45
|
-
fs.writeFileSync('./private-key', privateKey);
|
|
46
|
-
fs.writeFileSync('./public-key', publicKey);
|
|
41
|
+
### Create Private and Public keys
|
|
47
42
|
|
|
43
|
+
```js
|
|
44
|
+
const { privateKey, publicKey } = nodeRSA.createPrivateAndPublicKeys();
|
|
45
|
+
```
|
|
48
46
|
|
|
49
|
-
|
|
47
|
+
### Encrypt Text
|
|
50
48
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
```js
|
|
50
|
+
const encryptedText = encryptRsa.encryptStringWithRsaPublicKey({
|
|
51
|
+
text: 'hello world',
|
|
52
|
+
publicKey,
|
|
54
53
|
});
|
|
54
|
+
console.log(encryptedText);
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
//result: {
|
|
59
|
-
// encryptedText: 'QAoJBAj7ZqYR9Qb9vFGfpjBVY7BP0MtlPywyxMSodA7WmOmOn0glOlrLxUqjJrmaKsqxdJxZadEMAM8+6gLNhwcLtbFPRLQEUTSHk2NNhehsPOESoNjwbXOj5Y+zBCSkjVuW6MRkdaTZeGXi0sii1OqvIQGmOaOR2xzEdDj2eD8='
|
|
60
|
-
// }
|
|
56
|
+
// QMPLJN3KzvXxkll18wax+KxqC0UqiHrwMxYGNUmJWMi98diapGOL/WzliPP3bTrHu7yWU1DnaB3f71w6JBYP+wG98fWLaz8+rwemerVja8B0FJVUphjBUmoDhX52JSoLFI0YVHtihXtoRk1pVaRFWm8FmZPZAcCKL7a0YDI1wABGvcSbLhaacmgX6zR6fzyltWVCrXn0NcVGox7WK7x4sCtywNhZx2XuUVSztr7QYcV2OQe8aDTUd7NXtaBVkj9RUYUR2QvhIpETksx14WD4ytohM68RUIJLRmU3y761mxcF+7Pjw/Utcirqu2Ohg0K18xGqlaE6fdifh0vIlfH+kA==
|
|
57
|
+
```
|
|
61
58
|
|
|
62
|
-
|
|
59
|
+
### Decrypt Encrypted Text
|
|
63
60
|
|
|
61
|
+
```js
|
|
64
62
|
const decryptedText = nodeRSA.decryptStringWithRsaPrivateKey({
|
|
65
63
|
text: encryptedText,
|
|
66
|
-
|
|
64
|
+
privateKey
|
|
67
65
|
});
|
|
66
|
+
console.log(decryptedText);
|
|
67
|
+
// hello world
|
|
68
|
+
```
|
|
68
69
|
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
## Rsa Algorithm:
|
|
71
|
+
- [RSA Algorithm](https://simple.wikipedia.org/wiki/RSA_algorithm)
|
|
71
72
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
[https://
|
|
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,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "encrypt-rsa",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.1.2",
|
|
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": "
|
|
14
|
-
"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": "
|
|
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
|
-
"
|
|
23
|
-
"
|
|
26
|
+
"prepublish": "npm run build",
|
|
27
|
+
"husky": "husky",
|
|
28
|
+
"lint": "eslint",
|
|
24
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",
|
|
25
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",
|
|
26
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"
|
|
27
32
|
},
|
|
28
33
|
"devDependencies": {
|
|
29
34
|
"@types/chai": "^4.2.21",
|
|
30
|
-
"@types/mocha": "^
|
|
31
|
-
"@types/node": "^
|
|
32
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
33
|
-
"@typescript-eslint/parser": "^
|
|
35
|
+
"@types/mocha": "^9.1.1",
|
|
36
|
+
"@types/node": "^17.0.38",
|
|
37
|
+
"@typescript-eslint/eslint-plugin": "^5.27.0",
|
|
38
|
+
"@typescript-eslint/parser": "^5.27.0",
|
|
34
39
|
"chai": "^4.3.4",
|
|
35
40
|
"commitizen": "^4.2.4",
|
|
36
|
-
"docsify-cli": "^4.4.3",
|
|
37
41
|
"cz-conventional-changelog": "^3.3.0",
|
|
38
|
-
"
|
|
39
|
-
"eslint": "^
|
|
40
|
-
"eslint-config-airbnb-base": "^
|
|
42
|
+
"docsify-cli": "^4.4.3",
|
|
43
|
+
"eslint": "^8.16.0",
|
|
44
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
41
45
|
"eslint-plugin-import": "^2.23.4",
|
|
42
46
|
"generate-changelog": "^1.8.0",
|
|
43
47
|
"git-cz": "^4.7.6",
|
|
44
|
-
"husky": "^
|
|
45
|
-
"mocha": "^
|
|
46
|
-
"pinst": "^
|
|
48
|
+
"husky": "^8.0.1",
|
|
49
|
+
"mocha": "^10.0.0",
|
|
50
|
+
"pinst": "^3.0.0",
|
|
47
51
|
"ts-node": "^10.1.0",
|
|
48
52
|
"typescript": "^4.3.5"
|
|
49
53
|
},
|
|
@@ -80,5 +84,8 @@
|
|
|
80
84
|
"bugs": {
|
|
81
85
|
"url": "https://github.com/miladezzat/encrypt-rsa/issues"
|
|
82
86
|
},
|
|
83
|
-
"homepage": "https://encrypt-rsa.js.org"
|
|
87
|
+
"homepage": "https://encrypt-rsa.js.org",
|
|
88
|
+
"dependencies": {
|
|
89
|
+
"npm-check": "^5.9.2"
|
|
90
|
+
}
|
|
84
91
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
## 2.0.0 (2022-03-23)
|
|
2
|
-
|
|
3
|
-
##### Documentation Changes
|
|
4
|
-
|
|
5
|
-
* update docs ([e4e3f254](https://github.com/miladezzat/encrypt-rsa/commit/e4e3f254a4819922138f1e1763415207dc1591c6))
|
|
6
|
-
* update docs ([de0f8024](https://github.com/miladezzat/encrypt-rsa/commit/de0f8024aad85c591273f93b50952cd72e230693))
|
|
7
|
-
|
|
8
|
-
##### New Features
|
|
9
|
-
|
|
10
|
-
* make methods to take public and private keys as strings ([d47af0f5](https://github.com/miladezzat/encrypt-rsa/commit/d47af0f5c39d49cfb1589b0e236cc7c995bfb395))
|
|
11
|
-
* add new helper methods to decode and encode keys to base64 ([d3cba4c0](https://github.com/miladezzat/encrypt-rsa/commit/d3cba4c0f36d42e615f22c4ed4b828ed151faecb))
|
|
12
|
-
* update the docs ([4e470c6f](https://github.com/miladezzat/encrypt-rsa/commit/4e470c6feabfc828172bc484285239a24df064a4))
|
|
13
|
-
|
|
14
|
-
##### Tests
|
|
15
|
-
|
|
16
|
-
* add tests ([373d6c12](https://github.com/miladezzat/encrypt-rsa/commit/373d6c125184bd2e1394091def64280a5392413e))
|
|
17
|
-
|
|
18
|
-
#### 1.2.1 (2022-02-11)
|
|
19
|
-
|
|
20
|
-
##### Documentation Changes
|
|
21
|
-
|
|
22
|
-
* update docs ([846687b4](https://github.com/miladezzat/encrypt-rsa/commit/846687b4226bad946b2c0a20636ebec433c9005a))
|
|
23
|
-
|
|
24
|
-
##### New Features
|
|
25
|
-
|
|
26
|
-
* add encrypt-rsa.js.org ([3f6b0b4e](https://github.com/miladezzat/encrypt-rsa/commit/3f6b0b4e1fbc8082b9416f3dadd3be277a6e5c3f))
|
|
27
|
-
|
|
28
|
-
### 1.2.0 (2022-02-09)
|
|
29
|
-
|
|
30
|
-
##### Documentation Changes
|
|
31
|
-
|
|
32
|
-
* set docs ([6f1fa5e3](https://github.com/miladezzat/encrypt-rsa/commit/6f1fa5e38e7d1ef0576a8e49501766f540715477))
|
|
33
|
-
|
|
34
|
-
### 1.1.0 (2021-07-21)
|
|
35
|
-
|
|
36
|
-
##### Documentation Changes
|
|
37
|
-
|
|
38
|
-
* ✏️ update docs for creating keys ([cebb2758](https://github.com/miladezzat/encrypt-rsa/commit/cebb2758ac55478d46f0ae6228a10f8f1f78b8c3))
|
|
39
|
-
|
|
40
|
-
##### New Features
|
|
41
|
-
|
|
42
|
-
* 🎸 add create public and private keys ([74c51131](https://github.com/miladezzat/encrypt-rsa/commit/74c51131a858ad28cdda605b479b6bd21297e730))
|
|
43
|
-
|
|
44
|
-
#### 1.0.12 (2021-07-20)
|
|
45
|
-
|
|
46
|
-
##### Chores
|
|
47
|
-
|
|
48
|
-
* 🤖 update keywords ([b435e3ba](https://github.com/miladezzat/encrypt-rsa/commit/b435e3ba757a80dd66b95ed8a8a668952b66558e))
|
|
49
|
-
|
|
50
|
-
#### 1.0.11 (2021-07-20)
|
|
51
|
-
|
|
52
|
-
##### Bug Fixes
|
|
53
|
-
|
|
54
|
-
* 🐛 solve docs ([8a08c44e](https://github.com/miladezzat/encrypt-rsa/commit/8a08c44e767d5dcd242b5a5806602468cb663ec1))
|
|
55
|
-
|
|
56
|
-
#### 1.0.10 (2021-07-20)
|
|
57
|
-
|
|
58
|
-
##### Documentation Changes
|
|
59
|
-
|
|
60
|
-
* ✏️ update readme ([e29f1805](https://github.com/miladezzat/encrypt-rsa/commit/e29f180513d8f79daaad9fee7e0a532e2e94f076))
|
|
61
|
-
|
|
62
|
-
#### 1.0.9 (2021-07-19)
|
|
63
|
-
|
|
64
|
-
#### 1.0.8 (2021-07-19)
|
|
65
|
-
|
|
66
|
-
#### 1.0.8 (2021-07-19)
|
|
67
|
-
|
|
68
|
-
#### 1.0.5 (2021-07-19)
|
|
69
|
-
|
|
70
|
-
#### 1.0.4 (2021-07-19)
|
|
71
|
-
|
|
72
|
-
#### 1.0.4 (2021-07-19)
|
|
73
|
-
|
|
74
|
-
#### 1.0.3 (2021-07-19)
|
|
75
|
-
|
|
76
|
-
#### 1.0.2 (2021-07-19)
|
|
77
|
-
|
|
78
|
-
#### 1.0.1 (2021-07-19)
|
|
79
|
-
|
|
80
|
-
##### Other Changes
|
|
81
|
-
|
|
82
|
-
* miladezzat/rsa-node ([5f3c40de](https://github.com/miladezzat/encrypt-rsa/commit/5f3c40deb5cf9424bee39bfae4620866e828fcf8))
|
|
83
|
-
|
|
84
|
-
## 1.0.0 (2021-07-18)
|
|
85
|
-
|
|
86
|
-
##### Other Changes
|
|
87
|
-
|
|
88
|
-
* miladezzat/rsa-node (5f3c40de)
|
|
89
|
-
|