@pulkitsinha007/hybrid-crypto-js 1.2.1 → 1.2.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 +0 -18
- package/package.json +1 -1
- package/src/crypto.js +1 -33
- package/src/index.d.ts +1 -24
- package/src/index.js +0 -2
package/README.md
CHANGED
|
@@ -90,24 +90,6 @@ import { decryptWithSymmetricKey } from '@pulkitsinha007/hybrid-crypto-js';
|
|
|
90
90
|
const data = await decryptWithSymmetricKey({ encryptedData, iv }, sessionKey);
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
-
### `encrypt(data, publicKey)` (Helper)
|
|
94
|
-
Generates a new key, encrypts data, and wraps the key in one step.
|
|
95
|
-
- **Returns**: `Promise<{encryptedData, encryptedKey, iv}>`
|
|
96
|
-
|
|
97
|
-
```javascript
|
|
98
|
-
import { encrypt } from '@pulkitsinha007/hybrid-crypto-js';
|
|
99
|
-
const pkg = await encrypt("Secret", publicKey);
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
### `decrypt(encryptedPackage, privateKey)` (Helper)
|
|
103
|
-
Unwraps the key and decrypts the data in one step.
|
|
104
|
-
- **Returns**: `Promise<string | object>`
|
|
105
|
-
|
|
106
|
-
```javascript
|
|
107
|
-
import { decrypt } from '@pulkitsinha007/hybrid-crypto-js';
|
|
108
|
-
const msg = await decrypt(pkg, privateKey);
|
|
109
|
-
```
|
|
110
|
-
|
|
111
93
|
---
|
|
112
94
|
|
|
113
95
|
## Backend Setup (Dummy Application)
|
package/package.json
CHANGED
package/src/crypto.js
CHANGED
|
@@ -176,36 +176,4 @@ export async function unwrapKey(wrappedKey, privateKey) {
|
|
|
176
176
|
);
|
|
177
177
|
|
|
178
178
|
return key;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Encrypts data using hybrid encryption (Generates new AES key).
|
|
183
|
-
* @param {string|object} data - The payload to encrypt.
|
|
184
|
-
* @param {string} publicKey - The backend's public RSA key (Base64).
|
|
185
|
-
* @returns {Promise<{encryptedData: string, encryptedKey: string, iv: string}>}
|
|
186
|
-
*/
|
|
187
|
-
export async function encrypt(data, publicKey) {
|
|
188
|
-
const aesKey = await createSymmetricKey();
|
|
189
|
-
const { encryptedData, iv } = await encryptWithSymmetricKey(data, aesKey);
|
|
190
|
-
const encryptedKey = await wrapKey(aesKey, publicKey); // Reusing wrapKey
|
|
191
|
-
|
|
192
|
-
return {
|
|
193
|
-
encryptedData,
|
|
194
|
-
encryptedKey,
|
|
195
|
-
iv
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Decrypts data using hybrid encryption.
|
|
201
|
-
* @param {object} encryptedPackage - The encrypted package { encryptedData, encryptedKey, iv }.
|
|
202
|
-
* @param {string} privateKey - The backend's private RSA key (Base64).
|
|
203
|
-
* @returns {Promise<string|object>} The decrypted payload.
|
|
204
|
-
*/
|
|
205
|
-
export async function decrypt(encryptedPackage, privateKey) {
|
|
206
|
-
const { encryptedData, encryptedKey, iv } = encryptedPackage;
|
|
207
|
-
|
|
208
|
-
const aesKey = await unwrapKey(encryptedKey, privateKey); // Reusing unwrapKey
|
|
209
|
-
|
|
210
|
-
return await decryptWithSymmetricKey({ encryptedData, iv }, aesKey);
|
|
211
|
-
}
|
|
179
|
+
}
|
package/src/index.d.ts
CHANGED
|
@@ -91,27 +91,4 @@ export function wrapKey(key: CryptoKey, publicKey: string): Promise<string>;
|
|
|
91
91
|
* @param privateKey - The RSA private key (Base64).
|
|
92
92
|
* @returns The unwrapped AES key.
|
|
93
93
|
*/
|
|
94
|
-
export function unwrapKey(wrappedKey: string, privateKey: string): Promise<CryptoKey>;
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Encrypts data using hybrid encryption (Generates new AES key).
|
|
98
|
-
* @param data - The payload to encrypt.
|
|
99
|
-
* @param publicKey - The backend's public RSA key (Base64).
|
|
100
|
-
*/
|
|
101
|
-
export function encrypt(data: string | object, publicKey: string): Promise<{
|
|
102
|
-
encryptedData: string;
|
|
103
|
-
encryptedKey: string;
|
|
104
|
-
iv: string;
|
|
105
|
-
}>;
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Decrypts data using hybrid encryption.
|
|
109
|
-
* @param encryptedPackage - The encrypted package { encryptedData, encryptedKey, iv }.
|
|
110
|
-
* @param privateKey - The backend's private RSA key (Base64).
|
|
111
|
-
* @returns The decrypted payload.
|
|
112
|
-
*/
|
|
113
|
-
export function decrypt<T = any>(encryptedPackage: {
|
|
114
|
-
encryptedData: string;
|
|
115
|
-
encryptedKey: string;
|
|
116
|
-
iv: string;
|
|
117
|
-
}, privateKey: string): Promise<T>;
|
|
94
|
+
export function unwrapKey(wrappedKey: string, privateKey: string): Promise<CryptoKey>;
|