encrypt-rsa 3.1.1 → 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 CHANGED
@@ -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.
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.1.1",
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",