encrypt-rsa 3.3.0 → 4.0.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.
Files changed (39) hide show
  1. package/README.md +217 -154
  2. package/build/node/node/convertKetToBase64.d.ts +6 -0
  3. package/build/{functions → node/node}/convertKetToBase64.js +2 -7
  4. package/build/node/node/crypto.d.ts +6 -0
  5. package/build/node/node/crypto.js +98 -0
  6. package/build/node/node/index.d.ts +17 -0
  7. package/build/node/node/index.js +61 -0
  8. package/build/node/shared/helpers.d.ts +32 -0
  9. package/build/node/shared/helpers.js +101 -0
  10. package/build/{utils → node/shared}/types.d.ts +13 -0
  11. package/build/web/shared/helpers.d.ts +32 -0
  12. package/build/web/shared/helpers.js +101 -0
  13. package/build/web/shared/types.d.ts +68 -0
  14. package/build/web/shared/types.js +2 -0
  15. package/build/web/web/convertKetToBase64.d.ts +6 -0
  16. package/build/web/web/convertKetToBase64.js +13 -0
  17. package/build/web/web/crypto.d.ts +6 -0
  18. package/build/web/web/crypto.js +165 -0
  19. package/build/web/web/index.d.ts +17 -0
  20. package/build/web/web/index.js +77 -0
  21. package/package.json +24 -8
  22. package/build/functions/convertKetToBase64.d.ts +0 -11
  23. package/build/functions/createPrivateAndPublicKeys.d.ts +0 -17
  24. package/build/functions/createPrivateAndPublicKeys.js +0 -61
  25. package/build/functions/decrypt.d.ts +0 -19
  26. package/build/functions/decrypt.js +0 -53
  27. package/build/functions/decryptStringWithRsaPrivateKey.d.ts +0 -18
  28. package/build/functions/decryptStringWithRsaPrivateKey.js +0 -52
  29. package/build/functions/encrypt.d.ts +0 -19
  30. package/build/functions/encrypt.js +0 -53
  31. package/build/functions/encryptStringWithRsaPublicKey.d.ts +0 -19
  32. package/build/functions/encryptStringWithRsaPublicKey.js +0 -53
  33. package/build/functions/index.d.ts +0 -10
  34. package/build/functions/index.js +0 -35
  35. package/build/index.d.ts +0 -92
  36. package/build/index.js +0 -115
  37. package/build/utils/helpers.d.ts +0 -16
  38. package/build/utils/helpers.js +0 -35
  39. /package/build/{utils → node/shared}/types.js +0 -0
package/build/index.js DELETED
@@ -1,115 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- var convertKetToBase64_1 = __importDefault(require("./functions/convertKetToBase64"));
18
- var createPrivateAndPublicKeys_1 = __importDefault(require("./functions/createPrivateAndPublicKeys"));
19
- var decrypt_1 = __importDefault(require("./functions/decrypt"));
20
- var decryptStringWithRsaPrivateKey_1 = __importDefault(require("./functions/decryptStringWithRsaPrivateKey"));
21
- var encrypt_1 = __importDefault(require("./functions/encrypt"));
22
- var encryptStringWithRsaPublicKey_1 = __importDefault(require("./functions/encryptStringWithRsaPublicKey"));
23
- /**
24
- * NodeRSA class provides encryption and decryption methods using RSA keys.
25
- * It supports string and buffer encryption/decryption with both public and private keys.
26
- */
27
- var NodeRSA = /** @class */ (function () {
28
- /**
29
- * Constructs a new instance of the NodeRSA class.
30
- *
31
- * @param {string} [publicKey] - Optional public key for encryption.
32
- * @param {string} [privateKey] - Optional private key for decryption.
33
- * @param {number} [modulusLength=2048] - Length of the RSA modulus in bits.
34
- */
35
- function NodeRSA(publicKey, privateKey, modulusLength) {
36
- this.publicKey = publicKey;
37
- this.privateKey = privateKey;
38
- this.modulusLength = modulusLength || 2048;
39
- this.keyBase64 = 'base64';
40
- }
41
- /**
42
- * Encrypts a string using the RSA public key.
43
- *
44
- * @param {parametersOfEncrypt} args - Parameters for encryption, including the text and public key.
45
- * @returns {string} Encrypted string in base64 format.
46
- */
47
- NodeRSA.prototype.encryptStringWithRsaPublicKey = function (args) {
48
- var _a = args.publicKey, publicKey = _a === void 0 ? this.publicKey : _a;
49
- return (0, encryptStringWithRsaPublicKey_1.default)(__assign(__assign({}, args), { publicKey: (0, convertKetToBase64_1.default)(publicKey) }));
50
- };
51
- /**
52
- * Decrypts a string using the RSA private key.
53
- *
54
- * @param {parametersOfDecrypt} args - Parameters for decryption, including the encrypted text and private key.
55
- * @returns {string} Decrypted plain text string.
56
- */
57
- NodeRSA.prototype.decryptStringWithRsaPrivateKey = function (args) {
58
- var _a = args.privateKey, privateKey = _a === void 0 ? this.privateKey : _a;
59
- return (0, decryptStringWithRsaPrivateKey_1.default)(__assign(__assign({}, args), { privateKey: (0, convertKetToBase64_1.default)(privateKey) }));
60
- };
61
- /**
62
- * Encrypts a string using the RSA private key.
63
- *
64
- * @param {parametersOfEncryptPrivate} args - Parameters for encryption, including the text and private key.
65
- * @returns {string} Encrypted string in base64 format.
66
- */
67
- NodeRSA.prototype.encrypt = function (args) {
68
- var _a = args.privateKey, privateKey = _a === void 0 ? this.privateKey : _a;
69
- return (0, encrypt_1.default)(__assign(__assign({}, args), { privateKey: (0, convertKetToBase64_1.default)(privateKey) }));
70
- };
71
- /**
72
- * Decrypts a string using the RSA public key.
73
- *
74
- * @param {parametersOfDecryptPublic} args - Parameters for decryption, including the encrypted text and public key.
75
- * @returns {string} Decrypted plain text string.
76
- */
77
- NodeRSA.prototype.decrypt = function (args) {
78
- var _a = args.publicKey, publicKey = _a === void 0 ? this.publicKey : _a;
79
- return (0, decrypt_1.default)(__assign(__assign({}, args), { publicKey: (0, convertKetToBase64_1.default)(publicKey) }));
80
- };
81
- /**
82
- * Creates a pair of RSA private and public keys with the given modulus length.
83
- *
84
- * @param {number} [modulusLength=this.modulusLength] - Length of the RSA modulus in bits.
85
- * @returns {returnCreateKeys} The generated RSA private and public keys.
86
- */
87
- NodeRSA.prototype.createPrivateAndPublicKeys = function (modulusLength) {
88
- if (modulusLength === void 0) { modulusLength = this.modulusLength; }
89
- return (0, createPrivateAndPublicKeys_1.default)(modulusLength);
90
- };
91
- /**
92
- * Encrypts a buffer using the RSA public key.
93
- *
94
- * @param {Buffer} buffer - The buffer to encrypt.
95
- * @param {string} [publicKey] - Optional public key for encryption.
96
- * @returns {string} Encrypted buffer as a base64 string.
97
- */
98
- NodeRSA.prototype.encryptBufferWithRsaPublicKey = function (buffer, publicKey) {
99
- var base64String = buffer.toString(this.keyBase64);
100
- return this.encryptStringWithRsaPublicKey({ text: base64String, publicKey: publicKey });
101
- };
102
- /**
103
- * Decrypts a buffer using the RSA private key.
104
- *
105
- * @param {string} encryptedText - The encrypted base64 string to decrypt.
106
- * @param {string} [privateKey] - Optional private key for decryption.
107
- * @returns {Buffer} Decrypted buffer.
108
- */
109
- NodeRSA.prototype.decryptBufferWithRsaPrivateKey = function (encryptedText, privateKey) {
110
- var decryptedBase64 = this.decryptStringWithRsaPrivateKey({ text: encryptedText, privateKey: privateKey });
111
- return Buffer.from(decryptedBase64, this.keyBase64);
112
- };
113
- return NodeRSA;
114
- }());
115
- exports.default = NodeRSA;
@@ -1,16 +0,0 @@
1
- /**
2
- * Decodes a base64-encoded string into a UTF-8 string.
3
- *
4
- * @param {string} str - The base64-encoded string to decode.
5
- * @returns {string} The decoded UTF-8 string.
6
- * @throws {Error} If the input string cannot be decoded.
7
- */
8
- export declare const decode: (str: string) => string;
9
- /**
10
- * Encodes a UTF-8 string into a base64-encoded string.
11
- *
12
- * @param {string} str - The UTF-8 string to encode.
13
- * @returns {string} The base64-encoded string.
14
- * @throws {Error} If the input string cannot be encoded.
15
- */
16
- export declare const encode: (str: string) => string;
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.encode = exports.decode = void 0;
4
- /**
5
- * Decodes a base64-encoded string into a UTF-8 string.
6
- *
7
- * @param {string} str - The base64-encoded string to decode.
8
- * @returns {string} The decoded UTF-8 string.
9
- * @throws {Error} If the input string cannot be decoded.
10
- */
11
- var decode = function (str) {
12
- try {
13
- return Buffer.from(str, 'base64').toString('utf-8');
14
- }
15
- catch (error) {
16
- throw new Error('Failed to decode base64 string');
17
- }
18
- };
19
- exports.decode = decode;
20
- /**
21
- * Encodes a UTF-8 string into a base64-encoded string.
22
- *
23
- * @param {string} str - The UTF-8 string to encode.
24
- * @returns {string} The base64-encoded string.
25
- * @throws {Error} If the input string cannot be encoded.
26
- */
27
- var encode = function (str) {
28
- try {
29
- return Buffer.from(str, 'utf-8').toString('base64');
30
- }
31
- catch (error) {
32
- throw new Error('Failed to encode string to base64');
33
- }
34
- };
35
- exports.encode = encode;
File without changes