@ka-libs/crypto 1.3.1 → 1.3.3
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 +16 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,7 +43,7 @@ Built on native Web Crypto / Node\.js Crypto API, no third\-party dependencies\.
|
|
|
43
43
|
## 📦 Installation
|
|
44
44
|
|
|
45
45
|
```Plain Text
|
|
46
|
-
npm install ka-crypto
|
|
46
|
+
npm install @ka-libs/crypto
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
## 🚀 Quick Usage
|
|
@@ -51,7 +51,7 @@ npm install ka-crypto
|
|
|
51
51
|
### 1\. Generate RSA Key Pairs
|
|
52
52
|
|
|
53
53
|
```js
|
|
54
|
-
import { keyPairs } from 'ka-crypto';
|
|
54
|
+
import { keyPairs } from '@ka-libs/crypto';
|
|
55
55
|
|
|
56
56
|
// Return RSA public key / private key (PEM format)
|
|
57
57
|
const [publicKey, privateKey] = await keyPairs();
|
|
@@ -61,7 +61,7 @@ const [publicKey, privateKey] = await keyPairs();
|
|
|
61
61
|
### 2\. Hybrid Encrypt \(RSA \+ AES\)
|
|
62
62
|
|
|
63
63
|
```js
|
|
64
|
-
import { encrypt } from 'ka-crypto';
|
|
64
|
+
import { encrypt } from '@ka-libs/crypto';
|
|
65
65
|
|
|
66
66
|
// Param: plainData, RSA publicKey (PEM format)
|
|
67
67
|
const { data, valid } = await encrypt('any type of data', publicKey);
|
|
@@ -71,7 +71,7 @@ const { data, valid } = await encrypt('any type of data', publicKey);
|
|
|
71
71
|
### 3\. Hybrid Decrypt \(RSA \+ AES\)
|
|
72
72
|
|
|
73
73
|
```js
|
|
74
|
-
import { decrypt } from 'ka-crypto';
|
|
74
|
+
import { decrypt } from '@ka-libs/crypto';
|
|
75
75
|
|
|
76
76
|
// Param: data, valid, RSA privateKey (PEM format)
|
|
77
77
|
const plainData = await decrypt(data, valid, privateKey);
|
|
@@ -85,20 +85,20 @@ Support independent use of single encryption and decryption algorithm, flexible
|
|
|
85
85
|
### AES Encrypt / Decrypt \(AES\-256\-GCM\)
|
|
86
86
|
|
|
87
87
|
```js
|
|
88
|
-
import { aesEncrypt, aesDecrypt } from 'ka-crypto';
|
|
88
|
+
import { aesEncrypt, aesDecrypt } from '@ka-libs/crypto';
|
|
89
89
|
|
|
90
90
|
// AES encryption
|
|
91
|
-
const
|
|
91
|
+
const { data, payload } = await aesEncrypt('any type of data');
|
|
92
92
|
|
|
93
93
|
// AES decryption
|
|
94
|
-
const
|
|
94
|
+
const originData = aesDecrypt(cipherText, payload);
|
|
95
95
|
|
|
96
96
|
```
|
|
97
97
|
|
|
98
98
|
### RSA Encrypt / Decrypt \(RSA\-OAEP\-SHA1\)
|
|
99
99
|
|
|
100
100
|
```js
|
|
101
|
-
import { rsaEncrypt, rsaDecrypt } from 'ka-crypto';
|
|
101
|
+
import { rsaEncrypt, rsaDecrypt } from '@ka-libs/crypto';
|
|
102
102
|
|
|
103
103
|
// RSA public key encryption
|
|
104
104
|
const rsaCipher = rsaEncrypt(plainData, publicKey);
|
|
@@ -113,7 +113,7 @@ const originData = rsaDecrypt(rsaCipher, privateKey);
|
|
|
113
113
|
High\-quality pseudo\-random byte generation based on Mersenne Twister algorithm, used for custom IV / key random filling, consistent random logic across Node\.js and browsers\.
|
|
114
114
|
|
|
115
115
|
```js
|
|
116
|
-
import { getRandomValues } from 'ka-crypto';
|
|
116
|
+
import { getRandomValues } from '@ka-libs/crypto';
|
|
117
117
|
|
|
118
118
|
// Fill Uint8Array with secure random bytes (0-255)
|
|
119
119
|
const buf = new Uint8Array(16);
|
|
@@ -138,13 +138,13 @@ getRandomValues(buf);
|
|
|
138
138
|
Generate standard **RFC4122 Version 4 UUID**, based on internal Mersenne Twister random bytes, cross\-environment consistent and verifiable\.
|
|
139
139
|
|
|
140
140
|
```js
|
|
141
|
-
import {
|
|
141
|
+
import { uuidv4 } from '@ka-libs/crypto';
|
|
142
142
|
|
|
143
143
|
// Standard UUID (with dash)
|
|
144
|
-
const uuid =
|
|
144
|
+
const uuid = uuidv4(false);
|
|
145
145
|
|
|
146
146
|
// Simplified UUID (no dash)
|
|
147
|
-
const simpleUuid =
|
|
147
|
+
const simpleUuid = uuidv4(true);
|
|
148
148
|
|
|
149
149
|
```
|
|
150
150
|
|
|
@@ -185,7 +185,7 @@ Quickly generate standard RSA PEM key pairs \(public key \+ private key\) and au
|
|
|
185
185
|
### Usage
|
|
186
186
|
|
|
187
187
|
```js
|
|
188
|
-
import { exportKeyPairs } from 'ka-crypto';
|
|
188
|
+
import { exportKeyPairs } from '@ka-libs/crypto';
|
|
189
189
|
|
|
190
190
|
// Param: distPath (local folder path)
|
|
191
191
|
await exportKeyPairs('./keys');
|
|
@@ -217,12 +217,11 @@ After successful execution, two standard PEM key files will be generated in the
|
|
|
217
217
|
Unified transmission structure, directly JSON serializable for PHP backend docking:
|
|
218
218
|
|
|
219
219
|
```ts
|
|
220
|
+
type AesPayload = Base64UrlString // Base64 from Combined ArrayBuffer: AesKey(32) + AesIv(12) + AesTag(16)
|
|
221
|
+
|
|
220
222
|
interface CipherData {
|
|
221
223
|
data: string; // AES encrypted ciphertext (base64)
|
|
222
|
-
valid:
|
|
223
|
-
key: string; // RSA-OAEP-SHA1 encrypted AES key (base64)
|
|
224
|
-
iv: string; // AES-256-GCM initialization vector (base64)
|
|
225
|
-
},
|
|
224
|
+
valid: string; // RSA-OAEP-SHA1 encrypted AES Payload (base64)
|
|
226
225
|
}
|
|
227
226
|
|
|
228
227
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ka-libs/crypto",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.3",
|
|
4
4
|
"description": "Cross-environment crypto utility for Node.js & Browser, implement RSA-AES hybrid encryption based on native Web Crypto / Node.js crypto without third-party dependencies.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build:js": "rollup -c",
|