aes-bridge 2.0.5 → 2.0.6
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/.github/workflows/tests.yml +1 -1
- package/README.md +6 -4
- package/cli.js +11 -7
- package/dist/cbc.d.ts +20 -0
- package/dist/common.d.ts +25 -0
- package/dist/gcm.d.ts +20 -0
- package/dist/index.d.ts +6 -0
- package/dist/legacy.d.ts +10 -0
- package/dist/md5.d.ts +40 -0
- package/package.json +12 -4
- package/src/cbc.d.ts +20 -0
- package/src/common.d.ts +25 -0
- package/src/gcm.d.ts +20 -0
- package/src/index.d.ts +6 -0
- package/src/legacy.d.ts +10 -0
- package/src/md5.d.ts +40 -0
- package/tsconfig.json +17 -0
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# AesBridge JS
|
|
2
|
-
|
|
3
|
-
](https://www.npmjs.com/package/aes-bridge)
|
|
4
|
+
[](https://github.com/mervick/aes-bridge-js/actions/workflows/tests.yml)
|
|
4
5
|
|
|
5
6
|
**AesBridge** is a modern, secure, and cross-language **AES** encryption library. It offers a unified interface for encrypting and decrypting data across multiple programming languages. Supports **GCM**, **CBC**, and **legacy AES Everywhere** modes.
|
|
6
7
|
|
|
@@ -43,7 +44,7 @@ yarn add aes-bridge
|
|
|
43
44
|
|
|
44
45
|
#### CDN Option
|
|
45
46
|
```html
|
|
46
|
-
<script src="https://cdn.jsdelivr.net/npm/aes-bridge@v2.0.
|
|
47
|
+
<script src="https://cdn.jsdelivr.net/npm/aes-bridge@v2.0.5/dist/aes-bridge.umd.js"></script>
|
|
47
48
|
```
|
|
48
49
|
|
|
49
50
|
#### Node.js (ES Modules)
|
|
@@ -135,8 +136,9 @@ All functions in this library return a `Promise`. Specifically:
|
|
|
135
136
|
* `decrypt`, `decryptGcm`, `decryptGcmBin`, `decryptCbc`, `decryptCbcBin`, `decryptLegacy`
|
|
136
137
|
**Returns:** `Promise<Uint8Array>` - raw binary data.
|
|
137
138
|
|
|
139
|
+
---
|
|
138
140
|
|
|
139
|
-
|
|
141
|
+
### Converting `Uint8Array` to `string`
|
|
140
142
|
|
|
141
143
|
As noted above, decryption functions and binary encryption functions (those with `decrypt` or `Bin` in their name) return a `Promise<Uint8Array>`. If you need to convert this `Uint8Array` back into a human-readable string, you'll typically use the `TextDecoder` API, especially if the original data was a UTF-8 encoded string.
|
|
142
144
|
|
package/cli.js
CHANGED
|
@@ -85,15 +85,19 @@ program
|
|
|
85
85
|
throw new Error('Invalid decryption mode.');
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
const decoder = new TextDecoder('utf-8', { fatal: true });
|
|
89
|
-
decryptedResult = decoder.decode(decryptedResult);
|
|
90
|
-
|
|
91
88
|
if (options.b64) {
|
|
92
|
-
|
|
93
|
-
|
|
89
|
+
// If --b64, encode the decrypted result to base64.
|
|
90
|
+
let binaryString = '';
|
|
91
|
+
decryptedResult.forEach(byte => {
|
|
92
|
+
binaryString += String.fromCharCode(byte);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
console.log(btoa(binaryString));
|
|
94
96
|
} else {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
const decoder = new TextDecoder('utf-8', { fatal: true });
|
|
98
|
+
decryptedResult = decoder.decode(decryptedResult);
|
|
99
|
+
// Otherwise, assume it's UTF-8 and print.
|
|
100
|
+
console.log(decryptedResult.toString('utf8'));
|
|
97
101
|
}
|
|
98
102
|
} catch (error) {
|
|
99
103
|
console.error(`Error: ${error.message}`);
|
package/dist/cbc.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encrypts plaintext using AES-CBC + HMAC with derived key from password.
|
|
3
|
+
* Returns binary format: salt (16) + IV (16) + ciphertext + HMAC (32).
|
|
4
|
+
*/
|
|
5
|
+
export function encryptCbcBin(plaintext: string | Uint8Array, password: string | Uint8Array): Promise<Uint8Array>;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Decrypts binary data encrypted with `encryptCbcBin`.
|
|
9
|
+
*/
|
|
10
|
+
export function decryptCbcBin(data: string | Uint8Array, password: string | Uint8Array): Promise<Uint8Array>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Encrypts data and returns result as base64 string.
|
|
14
|
+
*/
|
|
15
|
+
export function encryptCbc(data: string | Uint8Array, password: string | Uint8Array): Promise<string>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Decrypts base64-encoded AES-CBC + HMAC data.
|
|
19
|
+
*/
|
|
20
|
+
export function decryptCbc(data: string, password: string | Uint8Array): Promise<Uint8Array>;
|
package/dist/common.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string to Uint8Array using UTF-8 encoding.
|
|
3
|
+
* If input is already Uint8Array, returns it as-is.
|
|
4
|
+
*/
|
|
5
|
+
export function toBytes(input: string | Uint8Array): Uint8Array;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Converts an Uint8Array to string using UTF-8 encoding.
|
|
9
|
+
*/
|
|
10
|
+
export function bytesToString(bytes: Uint8Array | string): string;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Generates a random Uint8Array of given length using secure crypto.
|
|
14
|
+
*/
|
|
15
|
+
export function generateRandom(length: number): Uint8Array;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Encodes bytes to base64 string.
|
|
19
|
+
*/
|
|
20
|
+
export function base64Encode(bytes: Uint8Array): string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Decodes base64 string to Uint8Array.
|
|
24
|
+
*/
|
|
25
|
+
export function base64Decode(b64: string): Uint8Array;
|
package/dist/gcm.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encrypts plaintext using AES-GCM with key derived from password.
|
|
3
|
+
* Output format: salt(16) + nonce(12) + ciphertext + tag(16)
|
|
4
|
+
*/
|
|
5
|
+
export function encryptGcmBin(plaintext: string | Uint8Array, password: string | Uint8Array): Promise<Uint8Array>;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Decrypts binary data produced by encryptGcmBin().
|
|
9
|
+
*/
|
|
10
|
+
export function decryptGcmBin(data: string | Uint8Array, password: string | Uint8Array): Promise<Uint8Array>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Encrypts data using AES-GCM and returns Base64 string.
|
|
14
|
+
*/
|
|
15
|
+
export function encryptGcm(data: string | Uint8Array, password: string | Uint8Array): Promise<string>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Decrypts Base64 encoded AES-GCM data.
|
|
19
|
+
*/
|
|
20
|
+
export function decryptGcm(data: string, password: string | Uint8Array): Promise<Uint8Array>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { encryptCbc, encryptCbcBin, decryptCbc, decryptCbcBin } from "./cbc";
|
|
2
|
+
export { encryptGcm, encryptGcmBin, decryptGcm, decryptGcmBin } from "./gcm";
|
|
3
|
+
export { encryptLegacy, decryptLegacy } from "./legacy";
|
|
4
|
+
|
|
5
|
+
export const encrypt: typeof import("./gcm").encryptGcm;
|
|
6
|
+
export const decrypt: typeof import("./gcm").decryptGcm;
|
package/dist/legacy.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encrypts plaintext using AES-256-CBC with OpenSSL-compatible format.
|
|
3
|
+
* Output: Base64 encoded "Salted__" + salt(8) + ciphertext
|
|
4
|
+
*/
|
|
5
|
+
export function encryptLegacy(raw: string | Uint8Array, passphrase: string | Uint8Array): Promise<string>;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Decrypts Base64-encoded AES-256-CBC data with OpenSSL-compatible format.
|
|
9
|
+
*/
|
|
10
|
+
export function decryptLegacy(enc: string, passphrase: string | Uint8Array): Promise<Uint8Array>;
|
package/dist/md5.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
type InputType = string | number[] | Uint8Array | ArrayBuffer;
|
|
2
|
+
|
|
3
|
+
interface Md5 {
|
|
4
|
+
update(message: InputType): Md5;
|
|
5
|
+
hex(): string;
|
|
6
|
+
toString(): string;
|
|
7
|
+
digest(): number[];
|
|
8
|
+
array(): number[];
|
|
9
|
+
arrayBuffer(): ArrayBuffer;
|
|
10
|
+
buffer(): ArrayBuffer;
|
|
11
|
+
base64(): string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface HmacMd5 extends Md5 {}
|
|
15
|
+
|
|
16
|
+
interface Md5Static {
|
|
17
|
+
(message: InputType): string;
|
|
18
|
+
hex(message: InputType): string;
|
|
19
|
+
array(message: InputType): number[];
|
|
20
|
+
digest(message: InputType): number[];
|
|
21
|
+
arrayBuffer(message: InputType): ArrayBuffer;
|
|
22
|
+
buffer(message: InputType): ArrayBuffer;
|
|
23
|
+
base64(message: InputType): string;
|
|
24
|
+
create(): Md5;
|
|
25
|
+
update(message: InputType): Md5;
|
|
26
|
+
hmac: {
|
|
27
|
+
(key: InputType, message: InputType): string;
|
|
28
|
+
hex(key: InputType, message: InputType): string;
|
|
29
|
+
array(key: InputType, message: InputType): number[];
|
|
30
|
+
digest(key: InputType, message: InputType): number[];
|
|
31
|
+
arrayBuffer(key: InputType, message: InputType): ArrayBuffer;
|
|
32
|
+
buffer(key: InputType, message: InputType): ArrayBuffer;
|
|
33
|
+
base64(key: InputType, message: InputType): string;
|
|
34
|
+
create(key: InputType): HmacMd5;
|
|
35
|
+
update(key: InputType, message: InputType): HmacMd5;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare const md5: Md5Static;
|
|
40
|
+
export default md5;
|
package/package.json
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aes-bridge",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
4
4
|
"description": "AesBridge is a modern, secure and cross-language AES encryption library",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/aes-bridge.umd.js",
|
|
7
7
|
"module": "dist/aes-bridge.esm.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
8
9
|
"exports": {
|
|
9
|
-
"import":
|
|
10
|
-
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/aes-bridge.esm.js"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/aes-bridge.umd.js"
|
|
17
|
+
}
|
|
11
18
|
},
|
|
12
19
|
"scripts": {
|
|
13
|
-
"build": "rollup -c",
|
|
20
|
+
"build": "rollup -c && npm run copy-types",
|
|
21
|
+
"copy-types": "cp src/*.d.ts dist/ 2>/dev/null || true",
|
|
14
22
|
"test": "vitest"
|
|
15
23
|
},
|
|
16
24
|
"repository": {
|
package/src/cbc.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encrypts plaintext using AES-CBC + HMAC with derived key from password.
|
|
3
|
+
* Returns binary format: salt (16) + IV (16) + ciphertext + HMAC (32).
|
|
4
|
+
*/
|
|
5
|
+
export function encryptCbcBin(plaintext: string | Uint8Array, password: string | Uint8Array): Promise<Uint8Array>;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Decrypts binary data encrypted with `encryptCbcBin`.
|
|
9
|
+
*/
|
|
10
|
+
export function decryptCbcBin(data: string | Uint8Array, password: string | Uint8Array): Promise<Uint8Array>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Encrypts data and returns result as base64 string.
|
|
14
|
+
*/
|
|
15
|
+
export function encryptCbc(data: string | Uint8Array, password: string | Uint8Array): Promise<string>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Decrypts base64-encoded AES-CBC + HMAC data.
|
|
19
|
+
*/
|
|
20
|
+
export function decryptCbc(data: string, password: string | Uint8Array): Promise<Uint8Array>;
|
package/src/common.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string to Uint8Array using UTF-8 encoding.
|
|
3
|
+
* If input is already Uint8Array, returns it as-is.
|
|
4
|
+
*/
|
|
5
|
+
export function toBytes(input: string | Uint8Array): Uint8Array;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Converts an Uint8Array to string using UTF-8 encoding.
|
|
9
|
+
*/
|
|
10
|
+
export function bytesToString(bytes: Uint8Array | string): string;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Generates a random Uint8Array of given length using secure crypto.
|
|
14
|
+
*/
|
|
15
|
+
export function generateRandom(length: number): Uint8Array;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Encodes bytes to base64 string.
|
|
19
|
+
*/
|
|
20
|
+
export function base64Encode(bytes: Uint8Array): string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Decodes base64 string to Uint8Array.
|
|
24
|
+
*/
|
|
25
|
+
export function base64Decode(b64: string): Uint8Array;
|
package/src/gcm.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encrypts plaintext using AES-GCM with key derived from password.
|
|
3
|
+
* Output format: salt(16) + nonce(12) + ciphertext + tag(16)
|
|
4
|
+
*/
|
|
5
|
+
export function encryptGcmBin(plaintext: string | Uint8Array, password: string | Uint8Array): Promise<Uint8Array>;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Decrypts binary data produced by encryptGcmBin().
|
|
9
|
+
*/
|
|
10
|
+
export function decryptGcmBin(data: string | Uint8Array, password: string | Uint8Array): Promise<Uint8Array>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Encrypts data using AES-GCM and returns Base64 string.
|
|
14
|
+
*/
|
|
15
|
+
export function encryptGcm(data: string | Uint8Array, password: string | Uint8Array): Promise<string>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Decrypts Base64 encoded AES-GCM data.
|
|
19
|
+
*/
|
|
20
|
+
export function decryptGcm(data: string, password: string | Uint8Array): Promise<Uint8Array>;
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { encryptCbc, encryptCbcBin, decryptCbc, decryptCbcBin } from "./cbc";
|
|
2
|
+
export { encryptGcm, encryptGcmBin, decryptGcm, decryptGcmBin } from "./gcm";
|
|
3
|
+
export { encryptLegacy, decryptLegacy } from "./legacy";
|
|
4
|
+
|
|
5
|
+
export const encrypt: typeof import("./gcm").encryptGcm;
|
|
6
|
+
export const decrypt: typeof import("./gcm").decryptGcm;
|
package/src/legacy.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encrypts plaintext using AES-256-CBC with OpenSSL-compatible format.
|
|
3
|
+
* Output: Base64 encoded "Salted__" + salt(8) + ciphertext
|
|
4
|
+
*/
|
|
5
|
+
export function encryptLegacy(raw: string | Uint8Array, passphrase: string | Uint8Array): Promise<string>;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Decrypts Base64-encoded AES-256-CBC data with OpenSSL-compatible format.
|
|
9
|
+
*/
|
|
10
|
+
export function decryptLegacy(enc: string, passphrase: string | Uint8Array): Promise<Uint8Array>;
|
package/src/md5.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
type InputType = string | number[] | Uint8Array | ArrayBuffer;
|
|
2
|
+
|
|
3
|
+
interface Md5 {
|
|
4
|
+
update(message: InputType): Md5;
|
|
5
|
+
hex(): string;
|
|
6
|
+
toString(): string;
|
|
7
|
+
digest(): number[];
|
|
8
|
+
array(): number[];
|
|
9
|
+
arrayBuffer(): ArrayBuffer;
|
|
10
|
+
buffer(): ArrayBuffer;
|
|
11
|
+
base64(): string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface HmacMd5 extends Md5 {}
|
|
15
|
+
|
|
16
|
+
interface Md5Static {
|
|
17
|
+
(message: InputType): string;
|
|
18
|
+
hex(message: InputType): string;
|
|
19
|
+
array(message: InputType): number[];
|
|
20
|
+
digest(message: InputType): number[];
|
|
21
|
+
arrayBuffer(message: InputType): ArrayBuffer;
|
|
22
|
+
buffer(message: InputType): ArrayBuffer;
|
|
23
|
+
base64(message: InputType): string;
|
|
24
|
+
create(): Md5;
|
|
25
|
+
update(message: InputType): Md5;
|
|
26
|
+
hmac: {
|
|
27
|
+
(key: InputType, message: InputType): string;
|
|
28
|
+
hex(key: InputType, message: InputType): string;
|
|
29
|
+
array(key: InputType, message: InputType): number[];
|
|
30
|
+
digest(key: InputType, message: InputType): number[];
|
|
31
|
+
arrayBuffer(key: InputType, message: InputType): ArrayBuffer;
|
|
32
|
+
buffer(key: InputType, message: InputType): ArrayBuffer;
|
|
33
|
+
base64(key: InputType, message: InputType): string;
|
|
34
|
+
create(key: InputType): HmacMd5;
|
|
35
|
+
update(key: InputType, message: InputType): HmacMd5;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare const md5: Md5Static;
|
|
40
|
+
export default md5;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"moduleResolution": "bundler",
|
|
4
|
+
"allowJs": true,
|
|
5
|
+
"esModuleInterop": true,
|
|
6
|
+
"allowSyntheticDefaultImports": true,
|
|
7
|
+
"target": "ES2020",
|
|
8
|
+
"module": "ESNext",
|
|
9
|
+
"lib": ["ES2020", "DOM"],
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"noEmit": true
|
|
12
|
+
},
|
|
13
|
+
"include": [
|
|
14
|
+
"src/**/*.js",
|
|
15
|
+
"src/**/*.d.ts"
|
|
16
|
+
]
|
|
17
|
+
}
|