encrypt-rsa 3.1.0 → 3.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 +29 -4
- package/build/index.d.ts +3 -0
- package/build/index.js +10 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -4,16 +4,16 @@
|
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
```bash
|
|
7
|
-
npm install
|
|
7
|
+
npm install encrypt-rsa
|
|
8
8
|
// OR
|
|
9
|
-
yarn add
|
|
9
|
+
yarn add encrypt-rsa
|
|
10
10
|
```
|
|
11
11
|
|
|
12
12
|
## Usage
|
|
13
13
|
**Importing the Library**
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
|
-
import NodeRSA from '
|
|
16
|
+
import NodeRSA from 'encrypt-rsa';
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
## Creating an Instance
|
|
@@ -174,6 +174,31 @@ const decryptedCredentials = nodeRSA.decryptStringWithRsaPrivateKey({ text: encr
|
|
|
174
174
|
console.log('Decrypted Credentials:', decryptedCredentials);
|
|
175
175
|
```
|
|
176
176
|
|
|
177
|
+
### Buffer Encryption/Decryption Methods:
|
|
178
|
+
|
|
179
|
+
1. `encryptBufferWithRsaPublicKey`: Converts a buffer to Base64 and then encrypts the Base64 string.
|
|
180
|
+
2. `decryptBufferWithRsaPrivateKey`: Decrypts the Base64 string and converts it back to a buffer.
|
|
181
|
+
|
|
182
|
+
#### Example Usage
|
|
183
|
+
```ts
|
|
184
|
+
const nodeRSA = new NodeRSA();
|
|
185
|
+
|
|
186
|
+
// Generate keys
|
|
187
|
+
const { publicKey, privateKey } = nodeRSA.createPrivateAndPublicKeys();
|
|
188
|
+
|
|
189
|
+
// Example buffer
|
|
190
|
+
const buffer = Buffer.from('This is some binary data');
|
|
191
|
+
|
|
192
|
+
// Encrypt the buffer
|
|
193
|
+
const encryptedBuffer = nodeRSA.encryptBufferWithRsaPublicKey(buffer, publicKey);
|
|
194
|
+
console.log('Encrypted Buffer:', encryptedBuffer);
|
|
195
|
+
|
|
196
|
+
// Decrypt back to buffer
|
|
197
|
+
const decryptedBuffer = nodeRSA.decryptBufferWithRsaPrivateKey(encryptedBuffer, privateKey);
|
|
198
|
+
console.log('Decrypted Buffer:', decryptedBuffer.toString()); // should log: 'This is some binary data'
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
|
|
177
202
|
#### Digital Signatures
|
|
178
203
|
|
|
179
204
|
Although not directly covered by the current implementation, RSA can also be used for creating and verifying digital signatures to ensure data integrity and authenticity.
|
|
@@ -185,7 +210,7 @@ We welcome contributions to the NodeRSA library! If you'd like to contribute, pl
|
|
|
185
210
|
1. Fork the repository on GitHub.
|
|
186
211
|
2. Clone your forked repository to your local machine.
|
|
187
212
|
```bash
|
|
188
|
-
git clone
|
|
213
|
+
git clone git@github.com:miladezzat/encrypt-rsa.git
|
|
189
214
|
```
|
|
190
215
|
3. Create a new branch for your feature or bugfix.
|
|
191
216
|
```bash
|
package/build/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { parametersOfDecrypt, parametersOfDecryptPublic, parametersOfEncrypt, parametersOfEncryptPrivate, returnCreateKeys } from './utils/types';
|
|
2
3
|
declare class NodeRSA {
|
|
3
4
|
private publicKey;
|
|
@@ -10,5 +11,7 @@ declare class NodeRSA {
|
|
|
10
11
|
encrypt(args: parametersOfEncryptPrivate): string;
|
|
11
12
|
decrypt(args: parametersOfDecryptPublic): string;
|
|
12
13
|
createPrivateAndPublicKeys(modulusLength?: number): returnCreateKeys;
|
|
14
|
+
encryptBufferWithRsaPublicKey(buffer: Buffer, publicKey?: string): string;
|
|
15
|
+
decryptBufferWithRsaPrivateKey(encryptedText: string, privateKey?: string): Buffer;
|
|
13
16
|
}
|
|
14
17
|
export default NodeRSA;
|
package/build/index.js
CHANGED
|
@@ -47,6 +47,16 @@ var NodeRSA = /** @class */ (function () {
|
|
|
47
47
|
if (modulusLength === void 0) { modulusLength = this.modulusLength; }
|
|
48
48
|
return (0, createPrivateAndPublicKeys_1.default)(modulusLength);
|
|
49
49
|
};
|
|
50
|
+
// Encrypt buffer using RSA public key (new)
|
|
51
|
+
NodeRSA.prototype.encryptBufferWithRsaPublicKey = function (buffer, publicKey) {
|
|
52
|
+
var base64String = buffer.toString(this.keyBase64);
|
|
53
|
+
return this.encryptStringWithRsaPublicKey({ text: base64String, publicKey: publicKey });
|
|
54
|
+
};
|
|
55
|
+
// Decrypt buffer using RSA private key (new)
|
|
56
|
+
NodeRSA.prototype.decryptBufferWithRsaPrivateKey = function (encryptedText, privateKey) {
|
|
57
|
+
var decryptedBase64 = this.decryptStringWithRsaPrivateKey({ text: encryptedText, privateKey: privateKey });
|
|
58
|
+
return Buffer.from(decryptedBase64, this.keyBase64);
|
|
59
|
+
};
|
|
50
60
|
return NodeRSA;
|
|
51
61
|
}());
|
|
52
62
|
exports.default = NodeRSA;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "encrypt-rsa",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.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",
|
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
"private key",
|
|
56
56
|
"rsa",
|
|
57
57
|
"node-rsa",
|
|
58
|
+
"encrypt-rsa",
|
|
58
59
|
"encrypt",
|
|
59
60
|
"encrypt by public key",
|
|
60
61
|
"decrypt by private key",
|