aes-bridge 2.0.4 → 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.
@@ -1,4 +1,4 @@
1
- name: Run Tests
1
+ name: Tests
2
2
 
3
3
  on:
4
4
  push:
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # AesBridge JS
2
- ![CI Status](https://github.com/mervick/aes-bridge-js/actions/workflows/tests.yml/badge.svg)
2
+
3
+ [![NPM Version](https://img.shields.io/npm/v/aes-bridge.svg)](https://www.npmjs.com/package/aes-bridge)
4
+ [![CI Status](https://github.com/mervick/aes-bridge-js/actions/workflows/tests.yml/badge.svg)](https://github.com/mervick/aes-bridge-js/actions/workflows/tests.yml)
3
5
 
4
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.
5
7
 
@@ -42,7 +44,7 @@ yarn add aes-bridge
42
44
 
43
45
  #### CDN Option
44
46
  ```html
45
- <script src="https://cdn.jsdelivr.net/npm/aes-bridge@v2.0.0/dist/aes-bridge.umd.js"></script>
47
+ <script src="https://cdn.jsdelivr.net/npm/aes-bridge@v2.0.5/dist/aes-bridge.umd.js"></script>
46
48
  ```
47
49
 
48
50
  #### Node.js (ES Modules)
@@ -63,41 +65,48 @@ const plaintext = await decrypt(ciphertext, 'MyStrongPass');
63
65
 
64
66
  - `encrypt(data, passphrase)`
65
67
  Encrypts a string using AES-GCM (default).
66
- **Returns:** base64-encoded string.
68
+ **Returns:** `Promise<string>` - base64-encoded string.
67
69
 
68
70
  - `decrypt(ciphertext, passphrase)`
69
- Decrypts a base64-encoded string encrypted with AES-GCM.
71
+ Decrypts a base64-encoded string encrypted with AES-GCM.
72
+ **Returns:** `Promise<Uint8Array>` - raw binary data.
70
73
 
71
74
  ### GCM Mode (recommended)
72
75
 
73
76
  - `encryptGcm(data, passphrase)`
74
- Encrypts a string using AES-GCM.
75
- **Returns:** base64-encoded string.
77
+ Encrypts a string using AES-GCM.
78
+ **Returns:** `Promise<string>` - base64-encoded string.
76
79
 
77
80
  - `decryptGcm(ciphertext, passphrase)`
78
- Decrypts a base64-encoded string encrypted with `encryptGcm`.
81
+ Decrypts a base64-encoded string encrypted with `encryptGcm`.
82
+ **Returns:** `Promise<Uint8Array>` - raw binary data.
79
83
 
80
84
  - `encryptGcmBin(data, passphrase)`
81
- Returns encrypted binary data using AES-GCM.
82
-
85
+ Returns encrypted binary data using AES-GCM.
86
+ **Returns:** `Promise<Uint8Array>` - raw binary data.
87
+
83
88
  - `decryptGcmBin(ciphertext, passphrase)`
84
- Decrypts binary data encrypted with `encryptGcmBin`.
89
+ Decrypts binary data encrypted with `encryptGcmBin`.
90
+ **Returns:** `Promise<Uint8Array>` - raw binary data.
85
91
 
86
92
  ### CBC Mode
87
93
 
88
94
  - `encryptCbc(data, passphrase)`
89
95
  Encrypts a string using AES-CBC.
90
96
  HMAC is used for integrity verification.
91
- **Returns:** base64-encoded string.
97
+ **Returns:** `Promise<string>` - base64-encoded string.
92
98
 
93
99
  - `decryptCbc(ciphertext, passphrase)`
94
- Decrypts a base64-encoded string encrypted with `encryptCbc` and verifies HMAC.
100
+ Decrypts a base64-encoded string encrypted with `encryptCbc` and verifies HMAC.
101
+ **Returns:** `Promise<Uint8Array>` - raw binary data.
95
102
 
96
103
  - `encryptCbcBin(data, passphrase)`
97
- Returns encrypted binary data using AES-CBC with HMAC.
104
+ Returns encrypted binary data using AES-CBC with HMAC.
105
+ **Returns:** `Promise<Uint8Array>` - raw binary data.
98
106
 
99
107
  - `decryptCbcBin(ciphertext, passphrase)`
100
- Decrypts binary data encrypted with `encryptCbcBin` and verifies HMAC.
108
+ Decrypts binary data encrypted with `encryptCbcBin` and verifies HMAC.
109
+ **Returns:** `Promise<Uint8Array>` - raw binary data.
101
110
 
102
111
  ### Legacy Compatibility
103
112
 
@@ -106,7 +115,49 @@ Their usage is strongly discouraged in new applications.
106
115
 
107
116
  - `encryptLegacy(data, passphrase)`
108
117
  Encrypts a string in the legacy AES Everywhere format.
118
+ **Returns:** `Promise<string>` - base64-encoded string.
109
119
 
110
120
  - `decryptLegacy(ciphertext, passphrase)`
111
- Decrypts a string encrypted in the legacy AES Everywhere format.
121
+ Decrypts a string encrypted in the legacy AES Everywhere format.
122
+ **Returns:** `Promise<Uint8Array>` - raw binary data.
123
+
124
+ ---
125
+
126
+ ### Return Types Overview
127
+
128
+ All functions in this library return a `Promise`. Specifically:
129
+
130
+ * `encrypt`, `encryptGcm`, `encryptCbc`, `encryptLegacy`
131
+ **Returns:** `Promise<string>` - typically base64-encoded string.
132
+
133
+ * `encryptGcmBin`, `encryptCbcBin`,
134
+ **Returns:** `Promise<Uint8Array>` - raw binary data.
135
+
136
+ * `decrypt`, `decryptGcm`, `decryptGcmBin`, `decryptCbc`, `decryptCbcBin`, `decryptLegacy`
137
+ **Returns:** `Promise<Uint8Array>` - raw binary data.
138
+
139
+ ---
140
+
141
+ ### Converting `Uint8Array` to `string`
142
+
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.
144
+
145
+ Here's an example of how you can convert the `Uint8Array` to a string:
146
+
147
+ ```javascript
148
+ // Assuming decryptedResult is a Promise<Uint8Array> from a decryption function
149
+ const decryptedUint8Array = await decryptedResult;
150
+ const decoder = new TextDecoder('utf-8', { fatal: true });
151
+ let finalStringResult;
152
+
153
+ try {
154
+ finalStringResult = decoder.decode(decryptedUint8Array);
155
+ console.log("Decrypted string:", finalStringResult);
156
+ } catch (e) {
157
+ console.error("Decoding failed:", e);
158
+ // Handle decoding errors, e.g., if the data is not valid UTF-8
159
+ }
160
+ ```
161
+
162
+ The `fatal: true` option in `TextDecoder` will throw an error if the input contains malformed UTF-8 sequences, which can be helpful for debugging or ensuring data integrity.
112
163
 
package/cli.js ADDED
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { Command } from 'commander';
4
+ import {
5
+ encryptCbc, decryptCbc
6
+ } from './src/cbc.js';
7
+ import {
8
+ encryptGcm, decryptGcm
9
+ } from './src/gcm.js';
10
+ import {
11
+ encryptLegacy, decryptLegacy
12
+ } from './src/legacy.js';
13
+
14
+ const program = new Command();
15
+
16
+ program
17
+ .name('aes-bridge-js')
18
+ .description('AES Encryption/Decryption CLI for AesBridge-JS.')
19
+ .version('2.0.5');
20
+
21
+ program
22
+ .command('encrypt')
23
+ .description('Encrypt data.')
24
+ .requiredOption('--mode <mode>', 'Encryption mode: cbc, gcm, or legacy.', ['cbc', 'gcm', 'legacy'])
25
+ .requiredOption('--data <data>', 'Data to encrypt (UTF-8 string or base64 if --b64 is used).')
26
+ .requiredOption('--passphrase <passphrase>', 'Passphrase for key derivation.')
27
+ .option('--b64', 'Expects base64 encoded input and returns base64 encoded output.', false)
28
+ .action(async (options) => {
29
+ try {
30
+ let dataToProcess = options.data;
31
+ if (options.b64) {
32
+ // If --b64 is true, data should be treated as base64 encoded.
33
+ // We decode it to a Buffer here to ensure consistent input type for encryption functions.
34
+ dataToProcess = Buffer.from(options.data, 'base64');
35
+ } else {
36
+ // If not --b64, treat as UTF-8 string.
37
+ dataToProcess = Buffer.from(options.data, 'utf8');
38
+ }
39
+
40
+ let result;
41
+ switch (options.mode) {
42
+ case 'cbc':
43
+ result = await encryptCbc(dataToProcess, options.passphrase);
44
+ break;
45
+ case 'gcm':
46
+ result = await encryptGcm(dataToProcess, options.passphrase);
47
+ break;
48
+ case 'legacy':
49
+ result = await encryptLegacy(dataToProcess, options.passphrase);
50
+ break;
51
+ default:
52
+ throw new Error('Invalid encryption mode.');
53
+ }
54
+ console.log(result.toString('utf8'));
55
+ } catch (error) {
56
+ console.error(`Error: ${error.message}`);
57
+ process.exit(1);
58
+ }
59
+ });
60
+
61
+ program
62
+ .command('decrypt')
63
+ .description('Decrypt data.')
64
+ .requiredOption('--mode <mode>', 'Encryption mode: cbc, gcm, or legacy.', ['cbc', 'gcm', 'legacy'])
65
+ .requiredOption('--data <data>', 'Data to decrypt (base64 string).')
66
+ .requiredOption('--passphrase <passphrase>', 'Passphrase for key derivation.')
67
+ .option('--b64', 'Returns base64 encoded output.', false)
68
+ .action(async (options) => {
69
+ try {
70
+ // Decryption functions expect base64 string as input.
71
+ const dataToProcess = options.data;
72
+
73
+ let decryptedResult;
74
+ switch (options.mode) {
75
+ case 'cbc':
76
+ decryptedResult = await decryptCbc(dataToProcess, options.passphrase);
77
+ break;
78
+ case 'gcm':
79
+ decryptedResult = await decryptGcm(dataToProcess, options.passphrase);
80
+ break;
81
+ case 'legacy':
82
+ decryptedResult = await decryptLegacy(dataToProcess, options.passphrase);
83
+ break;
84
+ default:
85
+ throw new Error('Invalid decryption mode.');
86
+ }
87
+
88
+ if (options.b64) {
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));
96
+ } else {
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'));
101
+ }
102
+ } catch (error) {
103
+ console.error(`Error: ${error.message}`);
104
+ process.exit(1);
105
+ }
106
+ });
107
+
108
+ program.parse(process.argv);
@@ -1,2 +1,2 @@
1
- "use strict";function t(t){return"string"==typeof t?(new TextEncoder).encode(t):t}function e(t){const e=new Uint8Array(t);return crypto.getRandomValues(e),e}function r(t){return btoa(String.fromCharCode(...t))}function n(t){t=function(t){return t instanceof Uint8Array?(new TextDecoder).decode(t):t}(t);const e=atob(t),r=new Uint8Array(e.length);for(let t=0;t<e.length;t++)r[t]=e.charCodeAt(t);return r}async function i(e,r){const n=await crypto.subtle.importKey("raw",t(e),{name:"PBKDF2"},!1,["deriveBits","deriveKey"]),i=await crypto.subtle.deriveBits({name:"PBKDF2",salt:r,iterations:1e5,hash:"SHA-256"},n,512),s=new Uint8Array(i);return{aesKey:await crypto.subtle.importKey("raw",s.slice(0,32),{name:"AES-CBC"},!1,["encrypt","decrypt"]),hmacKey:await crypto.subtle.importKey("raw",s.slice(32),{name:"HMAC",hash:"SHA-256"},!1,["sign","verify"])}}async function s(r,n){r=t(r),n=t(n);const s=e(16),a=e(16),{aesKey:h,hmacKey:o}=await i(n,s),c=new Uint8Array(await crypto.subtle.encrypt({name:"AES-CBC",iv:a},h,r)),y=new Uint8Array(a.length+c.length);y.set(a),y.set(c,a.length);const f=new Uint8Array(await crypto.subtle.sign("HMAC",o,y)),u=new Uint8Array(s.length+a.length+c.length+f.length);return u.set(s),u.set(a,s.length),u.set(c,s.length+a.length),u.set(f,s.length+a.length+c.length),u}async function a(e,r){e=t(e),r=t(r);const n=e.slice(0,16),s=e.slice(16,32),a=e.slice(-32),h=e.slice(32,-32),{aesKey:o,hmacKey:c}=await i(r,n),y=new Uint8Array(s.length+h.length);y.set(s),y.set(h,s.length);if(!await crypto.subtle.verify("HMAC",c,a,y))throw new Error("HMAC verification failed");return new Uint8Array(await crypto.subtle.decrypt({name:"AES-CBC",iv:s},o,h))}async function h(e,r){const n=await crypto.subtle.importKey("raw",t(e),{name:"PBKDF2"},!1,["deriveBits","deriveKey"]);return crypto.subtle.deriveKey({name:"PBKDF2",salt:r,iterations:1e5,hash:"SHA-256"},n,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}async function o(r,n){r=t(r),n=t(n);const i=e(16),s=e(12),a=await h(n,i),o=new Uint8Array(await crypto.subtle.encrypt({name:"AES-GCM",iv:s,tagLength:128},a,r)),c=new Uint8Array(i.length+s.length+o.length);return c.set(i),c.set(s,i.length),c.set(o,i.length+s.length),c}async function c(e,r){e=t(e),r=t(r);const n=e.slice(0,16),i=e.slice(16,28),s=e.slice(28),a=await h(r,n),o=await crypto.subtle.decrypt({name:"AES-GCM",iv:i,tagLength:128},a,s);return new Uint8Array(o)}async function y(t,e){return r(await o(t,e))}async function f(e,r){return c(n(t(e)),r)}var u,p="input is invalid type",l="object"==typeof process&&process.versions&&process.versions.node,d="undefined"!=typeof ArrayBuffer,w="0123456789abcdef".split(""),A=[128,32768,8388608,-2147483648],g=[0,8,16,24],b=["hex","array","digest","buffer","arrayBuffer","base64"],v="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),m=[];if(d){var B=new ArrayBuffer(68);u=new Uint8Array(B),m=new Uint32Array(B)}var C=Array.isArray;C||(C=function(t){return"[object Array]"===Object.prototype.toString.call(t)});var U=ArrayBuffer.isView;d&&!U&&(U=function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer});var x=function(t){var e=typeof t;if("string"===e)return[t,!0];if("object"!==e||null===t)throw new Error(p);if(d&&t.constructor===ArrayBuffer)return[new Uint8Array(t),!1];if(!C(t)&&!U(t))throw new Error(p);return[t,!1]},K=function(t){return function(e){return new E(!0).update(e)[t]()}},S=function(t){var e,r=require("crypto"),n=require("buffer").Buffer;e=n.from?n.from:function(t){return new n(t)};return function(i){if("string"==typeof i)return r.createHash("md5").update(i,"utf8").digest("hex");if(null==i)throw new Error(p);return i.constructor===ArrayBuffer&&(i=new Uint8Array(i)),C(i)||U(i)||i.constructor===n?r.createHash("md5").update(e(i)).digest("hex"):t(i)}};function E(t){if(t)m[0]=m[16]=m[1]=m[2]=m[3]=m[4]=m[5]=m[6]=m[7]=m[8]=m[9]=m[10]=m[11]=m[12]=m[13]=m[14]=m[15]=0,this.blocks=m,this.buffer8=u;else if(d){var e=new ArrayBuffer(68);this.buffer8=new Uint8Array(e),this.blocks=new Uint32Array(e)}else this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.h0=this.h1=this.h2=this.h3=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0}function z(t,e){var r,n=x(t);if(t=n[0],n[1]){var i,s=[],a=t.length,h=0;for(r=0;r<a;++r)(i=t.charCodeAt(r))<128?s[h++]=i:i<2048?(s[h++]=192|i>>>6,s[h++]=128|63&i):i<55296||i>=57344?(s[h++]=224|i>>>12,s[h++]=128|i>>>6&63,s[h++]=128|63&i):(i=65536+((1023&i)<<10|1023&t.charCodeAt(++r)),s[h++]=240|i>>>18,s[h++]=128|i>>>12&63,s[h++]=128|i>>>6&63,s[h++]=128|63&i);t=s}t.length>64&&(t=new E(!0).update(t).array());var o=[],c=[];for(r=0;r<64;++r){var y=t[r]||0;o[r]=92^y,c[r]=54^y}E.call(this,e),this.update(c),this.oKeyPad=o,this.inner=!0,this.sharedMemory=e}E.prototype.update=function(t){if(this.finalized)throw new Error("finalize already called");var e=x(t);t=e[0];for(var r,n,i=e[1],s=0,a=t.length,h=this.blocks,o=this.buffer8;s<a;){if(this.hashed&&(this.hashed=!1,h[0]=h[16],h[16]=h[1]=h[2]=h[3]=h[4]=h[5]=h[6]=h[7]=h[8]=h[9]=h[10]=h[11]=h[12]=h[13]=h[14]=h[15]=0),i)if(d)for(n=this.start;s<a&&n<64;++s)(r=t.charCodeAt(s))<128?o[n++]=r:r<2048?(o[n++]=192|r>>>6,o[n++]=128|63&r):r<55296||r>=57344?(o[n++]=224|r>>>12,o[n++]=128|r>>>6&63,o[n++]=128|63&r):(r=65536+((1023&r)<<10|1023&t.charCodeAt(++s)),o[n++]=240|r>>>18,o[n++]=128|r>>>12&63,o[n++]=128|r>>>6&63,o[n++]=128|63&r);else for(n=this.start;s<a&&n<64;++s)(r=t.charCodeAt(s))<128?h[n>>>2]|=r<<g[3&n++]:r<2048?(h[n>>>2]|=(192|r>>>6)<<g[3&n++],h[n>>>2]|=(128|63&r)<<g[3&n++]):r<55296||r>=57344?(h[n>>>2]|=(224|r>>>12)<<g[3&n++],h[n>>>2]|=(128|r>>>6&63)<<g[3&n++],h[n>>>2]|=(128|63&r)<<g[3&n++]):(r=65536+((1023&r)<<10|1023&t.charCodeAt(++s)),h[n>>>2]|=(240|r>>>18)<<g[3&n++],h[n>>>2]|=(128|r>>>12&63)<<g[3&n++],h[n>>>2]|=(128|r>>>6&63)<<g[3&n++],h[n>>>2]|=(128|63&r)<<g[3&n++]);else if(d)for(n=this.start;s<a&&n<64;++s)o[n++]=t[s];else for(n=this.start;s<a&&n<64;++s)h[n>>>2]|=t[s]<<g[3&n++];this.lastByteIndex=n,this.bytes+=n-this.start,n>=64?(this.start=n-64,this.hash(),this.hashed=!0):this.start=n}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296|0,this.bytes=this.bytes%4294967296),this},E.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,e=this.lastByteIndex;t[e>>>2]|=A[3&e],e>=56&&(this.hashed||this.hash(),t[0]=t[16],t[16]=t[1]=t[2]=t[3]=t[4]=t[5]=t[6]=t[7]=t[8]=t[9]=t[10]=t[11]=t[12]=t[13]=t[14]=t[15]=0),t[14]=this.bytes<<3,t[15]=this.hBytes<<3|this.bytes>>>29,this.hash()}},E.prototype.hash=function(){var t,e,r,n,i,s,a=this.blocks;this.first?e=((e=((t=((t=a[0]-680876937)<<7|t>>>25)-271733879|0)^(r=((r=(-271733879^(n=((n=(-1732584194^2004318071&t)+a[1]-117830708)<<12|n>>>20)+t|0)&(-271733879^t))+a[2]-1126478375)<<17|r>>>15)+n|0)&(n^t))+a[3]-1316259209)<<22|e>>>10)+r|0:(t=this.h0,e=this.h1,r=this.h2,e=((e+=((t=((t+=((n=this.h3)^e&(r^n))+a[0]-680876936)<<7|t>>>25)+e|0)^(r=((r+=(e^(n=((n+=(r^t&(e^r))+a[1]-389564586)<<12|n>>>20)+t|0)&(t^e))+a[2]+606105819)<<17|r>>>15)+n|0)&(n^t))+a[3]-1044525330)<<22|e>>>10)+r|0),e=((e+=((t=((t+=(n^e&(r^n))+a[4]-176418897)<<7|t>>>25)+e|0)^(r=((r+=(e^(n=((n+=(r^t&(e^r))+a[5]+1200080426)<<12|n>>>20)+t|0)&(t^e))+a[6]-1473231341)<<17|r>>>15)+n|0)&(n^t))+a[7]-45705983)<<22|e>>>10)+r|0,e=((e+=((t=((t+=(n^e&(r^n))+a[8]+1770035416)<<7|t>>>25)+e|0)^(r=((r+=(e^(n=((n+=(r^t&(e^r))+a[9]-1958414417)<<12|n>>>20)+t|0)&(t^e))+a[10]-42063)<<17|r>>>15)+n|0)&(n^t))+a[11]-1990404162)<<22|e>>>10)+r|0,e=((e+=((t=((t+=(n^e&(r^n))+a[12]+1804603682)<<7|t>>>25)+e|0)^(r=((r+=(e^(n=((n+=(r^t&(e^r))+a[13]-40341101)<<12|n>>>20)+t|0)&(t^e))+a[14]-1502002290)<<17|r>>>15)+n|0)&(n^t))+a[15]+1236535329)<<22|e>>>10)+r|0,e=((e+=((n=((n+=(e^r&((t=((t+=(r^n&(e^r))+a[1]-165796510)<<5|t>>>27)+e|0)^e))+a[6]-1069501632)<<9|n>>>23)+t|0)^t&((r=((r+=(t^e&(n^t))+a[11]+643717713)<<14|r>>>18)+n|0)^n))+a[0]-373897302)<<20|e>>>12)+r|0,e=((e+=((n=((n+=(e^r&((t=((t+=(r^n&(e^r))+a[5]-701558691)<<5|t>>>27)+e|0)^e))+a[10]+38016083)<<9|n>>>23)+t|0)^t&((r=((r+=(t^e&(n^t))+a[15]-660478335)<<14|r>>>18)+n|0)^n))+a[4]-405537848)<<20|e>>>12)+r|0,e=((e+=((n=((n+=(e^r&((t=((t+=(r^n&(e^r))+a[9]+568446438)<<5|t>>>27)+e|0)^e))+a[14]-1019803690)<<9|n>>>23)+t|0)^t&((r=((r+=(t^e&(n^t))+a[3]-187363961)<<14|r>>>18)+n|0)^n))+a[8]+1163531501)<<20|e>>>12)+r|0,e=((e+=((n=((n+=(e^r&((t=((t+=(r^n&(e^r))+a[13]-1444681467)<<5|t>>>27)+e|0)^e))+a[2]-51403784)<<9|n>>>23)+t|0)^t&((r=((r+=(t^e&(n^t))+a[7]+1735328473)<<14|r>>>18)+n|0)^n))+a[12]-1926607734)<<20|e>>>12)+r|0,e=((e+=((s=(n=((n+=((i=e^r)^(t=((t+=(i^n)+a[5]-378558)<<4|t>>>28)+e|0))+a[8]-2022574463)<<11|n>>>21)+t|0)^t)^(r=((r+=(s^e)+a[11]+1839030562)<<16|r>>>16)+n|0))+a[14]-35309556)<<23|e>>>9)+r|0,e=((e+=((s=(n=((n+=((i=e^r)^(t=((t+=(i^n)+a[1]-1530992060)<<4|t>>>28)+e|0))+a[4]+1272893353)<<11|n>>>21)+t|0)^t)^(r=((r+=(s^e)+a[7]-155497632)<<16|r>>>16)+n|0))+a[10]-1094730640)<<23|e>>>9)+r|0,e=((e+=((s=(n=((n+=((i=e^r)^(t=((t+=(i^n)+a[13]+681279174)<<4|t>>>28)+e|0))+a[0]-358537222)<<11|n>>>21)+t|0)^t)^(r=((r+=(s^e)+a[3]-722521979)<<16|r>>>16)+n|0))+a[6]+76029189)<<23|e>>>9)+r|0,e=((e+=((s=(n=((n+=((i=e^r)^(t=((t+=(i^n)+a[9]-640364487)<<4|t>>>28)+e|0))+a[12]-421815835)<<11|n>>>21)+t|0)^t)^(r=((r+=(s^e)+a[15]+530742520)<<16|r>>>16)+n|0))+a[2]-995338651)<<23|e>>>9)+r|0,e=((e+=((n=((n+=(e^((t=((t+=(r^(e|~n))+a[0]-198630844)<<6|t>>>26)+e|0)|~r))+a[7]+1126891415)<<10|n>>>22)+t|0)^((r=((r+=(t^(n|~e))+a[14]-1416354905)<<15|r>>>17)+n|0)|~t))+a[5]-57434055)<<21|e>>>11)+r|0,e=((e+=((n=((n+=(e^((t=((t+=(r^(e|~n))+a[12]+1700485571)<<6|t>>>26)+e|0)|~r))+a[3]-1894986606)<<10|n>>>22)+t|0)^((r=((r+=(t^(n|~e))+a[10]-1051523)<<15|r>>>17)+n|0)|~t))+a[1]-2054922799)<<21|e>>>11)+r|0,e=((e+=((n=((n+=(e^((t=((t+=(r^(e|~n))+a[8]+1873313359)<<6|t>>>26)+e|0)|~r))+a[15]-30611744)<<10|n>>>22)+t|0)^((r=((r+=(t^(n|~e))+a[6]-1560198380)<<15|r>>>17)+n|0)|~t))+a[13]+1309151649)<<21|e>>>11)+r|0,e=((e+=((n=((n+=(e^((t=((t+=(r^(e|~n))+a[4]-145523070)<<6|t>>>26)+e|0)|~r))+a[11]-1120210379)<<10|n>>>22)+t|0)^((r=((r+=(t^(n|~e))+a[2]+718787259)<<15|r>>>17)+n|0)|~t))+a[9]-343485551)<<21|e>>>11)+r|0,this.first?(this.h0=t+1732584193|0,this.h1=e-271733879|0,this.h2=r-1732584194|0,this.h3=n+271733878|0,this.first=!1):(this.h0=this.h0+t|0,this.h1=this.h1+e|0,this.h2=this.h2+r|0,this.h3=this.h3+n|0)},E.prototype.hex=function(){this.finalize();var t=this.h0,e=this.h1,r=this.h2,n=this.h3;return w[t>>>4&15]+w[15&t]+w[t>>>12&15]+w[t>>>8&15]+w[t>>>20&15]+w[t>>>16&15]+w[t>>>28&15]+w[t>>>24&15]+w[e>>>4&15]+w[15&e]+w[e>>>12&15]+w[e>>>8&15]+w[e>>>20&15]+w[e>>>16&15]+w[e>>>28&15]+w[e>>>24&15]+w[r>>>4&15]+w[15&r]+w[r>>>12&15]+w[r>>>8&15]+w[r>>>20&15]+w[r>>>16&15]+w[r>>>28&15]+w[r>>>24&15]+w[n>>>4&15]+w[15&n]+w[n>>>12&15]+w[n>>>8&15]+w[n>>>20&15]+w[n>>>16&15]+w[n>>>28&15]+w[n>>>24&15]},E.prototype.toString=E.prototype.hex,E.prototype.digest=function(){this.finalize();var t=this.h0,e=this.h1,r=this.h2,n=this.h3;return[255&t,t>>>8&255,t>>>16&255,t>>>24&255,255&e,e>>>8&255,e>>>16&255,e>>>24&255,255&r,r>>>8&255,r>>>16&255,r>>>24&255,255&n,n>>>8&255,n>>>16&255,n>>>24&255]},E.prototype.array=E.prototype.digest,E.prototype.arrayBuffer=function(){this.finalize();var t=new ArrayBuffer(16),e=new Uint32Array(t);return e[0]=this.h0,e[1]=this.h1,e[2]=this.h2,e[3]=this.h3,t},E.prototype.buffer=E.prototype.arrayBuffer,E.prototype.base64=function(){for(var t,e,r,n="",i=this.array(),s=0;s<15;)t=i[s++],e=i[s++],r=i[s++],n+=v[t>>>2]+v[63&(t<<4|e>>>4)]+v[63&(e<<2|r>>>6)]+v[63&r];return t=i[s],n+=v[t>>>2]+v[t<<4&63]+"=="},z.prototype=new E,z.prototype.finalize=function(){if(E.prototype.finalize.call(this),this.inner){this.inner=!1;var t=this.array();E.call(this,this.sharedMemory),this.update(this.oKeyPad),this.update(t),E.prototype.finalize.call(this)}};const k=function(){var t=K("hex");l&&(t=S(t)),t.create=function(){return new E},t.update=function(e){return t.create().update(e)};for(var e=0;e<b.length;++e){var r=b[e];t[r]=K(r)}return t}();async function H(e,r){e=t(e);let n=new Uint8Array(0),i=new Uint8Array(0);for(;n.length<48;){i=M(G(i,e,r)),n=G(n,i)}const s=n.slice(0,32),a=n.slice(32,48);return{key:await crypto.subtle.importKey("raw",s,"AES-CBC",!1,["encrypt","decrypt"]),iv:a}}function M(t){const e=t instanceof Uint8Array?Buffer.from(t):t,r=k(e);return new Uint8Array(Buffer.from(r,"hex"))}function G(...t){const e=t.reduce((t,e)=>t+e.length,0),r=new Uint8Array(e);let n=0;for(const e of t)r.set(e,n),n+=e.length;return r}const P=y,j=f;exports.decrypt=j,exports.decryptCbc=async function(t,e){return a(n(t),e)},exports.decryptCbcBin=a,exports.decryptGcm=f,exports.decryptGcmBin=c,exports.decryptLegacy=async function(t,e){const r=n(t);if("Salted__"!==String.fromCharCode(...r.slice(0,8)))throw new Error("Invalid OpenSSL header");const i=r.slice(8,16),{key:s,iv:a}=await H(e,i);return new Uint8Array(await crypto.subtle.decrypt({name:"AES-CBC",iv:a},s,r.slice(16)))},exports.encrypt=P,exports.encryptCbc=async function(t,e){return r(await s(t,e))},exports.encryptCbcBin=s,exports.encryptGcm=y,exports.encryptGcmBin=o,exports.encryptLegacy=async function(n,i){const s=e(8),{key:a,iv:h}=await H(i,s),o=new Uint8Array(await crypto.subtle.encrypt({name:"AES-CBC",iv:h},a,t(n))),c=new Uint8Array(16+o.length);return c.set(t("Salted__")),c.set(s,8),c.set(o,16),r(c)};
1
+ "use strict";function t(t){return"string"==typeof t?(new TextEncoder).encode(t):t}function e(t){const e=new Uint8Array(t);return crypto.getRandomValues(e),e}function r(t){return btoa(String.fromCharCode(...t))}function n(t){t=function(t){return t instanceof Uint8Array?(new TextDecoder).decode(t):t}(t);const e=atob(t),r=new Uint8Array(e.length);for(let t=0;t<e.length;t++)r[t]=e.charCodeAt(t);return r}async function i(e,r){const n=await crypto.subtle.importKey("raw",t(e),{name:"PBKDF2"},!1,["deriveBits","deriveKey"]),i=await crypto.subtle.deriveBits({name:"PBKDF2",salt:r,iterations:1e5,hash:"SHA-256"},n,512),s=new Uint8Array(i);return{aesKey:await crypto.subtle.importKey("raw",s.slice(0,32),{name:"AES-CBC"},!1,["encrypt","decrypt"]),hmacKey:await crypto.subtle.importKey("raw",s.slice(32),{name:"HMAC",hash:"SHA-256"},!1,["sign","verify"])}}async function s(r,n){r=t(r),n=t(n);const s=e(16),a=e(16),{aesKey:h,hmacKey:o}=await i(n,s),c=new Uint8Array(await crypto.subtle.encrypt({name:"AES-CBC",iv:a},h,r)),y=new Uint8Array(a.length+c.length);y.set(a),y.set(c,a.length);const f=new Uint8Array(await crypto.subtle.sign("HMAC",o,y)),u=new Uint8Array(s.length+a.length+c.length+f.length);return u.set(s),u.set(a,s.length),u.set(c,s.length+a.length),u.set(f,s.length+a.length+c.length),u}async function a(e,r){e=t(e),r=t(r);const n=e.slice(0,16),s=e.slice(16,32),a=e.slice(-32),h=e.slice(32,-32),{aesKey:o,hmacKey:c}=await i(r,n),y=new Uint8Array(s.length+h.length);y.set(s),y.set(h,s.length);if(!await crypto.subtle.verify("HMAC",c,a,y))throw new Error("HMAC verification failed");return new Uint8Array(await crypto.subtle.decrypt({name:"AES-CBC",iv:s},o,h))}async function h(e,r){const n=await crypto.subtle.importKey("raw",t(e),{name:"PBKDF2"},!1,["deriveBits","deriveKey"]);return crypto.subtle.deriveKey({name:"PBKDF2",salt:r,iterations:1e5,hash:"SHA-256"},n,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}async function o(r,n){r=t(r),n=t(n);const i=e(16),s=e(12),a=await h(n,i),o=new Uint8Array(await crypto.subtle.encrypt({name:"AES-GCM",iv:s,tagLength:128},a,r)),c=new Uint8Array(i.length+s.length+o.length);return c.set(i),c.set(s,i.length),c.set(o,i.length+s.length),c}async function c(e,r){e=t(e),r=t(r);const n=e.slice(0,16),i=e.slice(16,28),s=e.slice(28),a=await h(r,n),o=await crypto.subtle.decrypt({name:"AES-GCM",iv:i,tagLength:128},a,s);return new Uint8Array(o)}async function y(t,e){return r(await o(t,e))}async function f(e,r){return c(n(t(e)),r)}var u="input is invalid type";"object"==typeof process&&process.versions&&process.versions.node;var l,p="undefined"!=typeof ArrayBuffer,d="0123456789abcdef".split(""),w=[128,32768,8388608,-2147483648],A=[0,8,16,24],g=["hex","array","digest","buffer","arrayBuffer","base64"],b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),v=[];if(p){var B=new ArrayBuffer(68);l=new Uint8Array(B),v=new Uint32Array(B)}var C=Array.isArray;C||(C=function(t){return"[object Array]"===Object.prototype.toString.call(t)});var m=ArrayBuffer.isView;p&&!m&&(m=function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer});var U=function(t){var e=typeof t;if("string"===e)return[t,!0];if("object"!==e||null===t)throw new Error(u);if(p&&t.constructor===ArrayBuffer)return[new Uint8Array(t),!1];if(!C(t)&&!m(t))throw new Error(u);return[t,!1]},x=function(t){return function(e){return new K(!0).update(e)[t]()}};function K(t){if(t)v[0]=v[16]=v[1]=v[2]=v[3]=v[4]=v[5]=v[6]=v[7]=v[8]=v[9]=v[10]=v[11]=v[12]=v[13]=v[14]=v[15]=0,this.blocks=v,this.buffer8=l;else if(p){var e=new ArrayBuffer(68);this.buffer8=new Uint8Array(e),this.blocks=new Uint32Array(e)}else this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.h0=this.h1=this.h2=this.h3=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0}function S(t,e){var r,n=U(t);if(t=n[0],n[1]){var i,s=[],a=t.length,h=0;for(r=0;r<a;++r)(i=t.charCodeAt(r))<128?s[h++]=i:i<2048?(s[h++]=192|i>>>6,s[h++]=128|63&i):i<55296||i>=57344?(s[h++]=224|i>>>12,s[h++]=128|i>>>6&63,s[h++]=128|63&i):(i=65536+((1023&i)<<10|1023&t.charCodeAt(++r)),s[h++]=240|i>>>18,s[h++]=128|i>>>12&63,s[h++]=128|i>>>6&63,s[h++]=128|63&i);t=s}t.length>64&&(t=new K(!0).update(t).array());var o=[],c=[];for(r=0;r<64;++r){var y=t[r]||0;o[r]=92^y,c[r]=54^y}K.call(this,e),this.update(c),this.oKeyPad=o,this.inner=!0,this.sharedMemory=e}K.prototype.update=function(t){if(this.finalized)throw new Error("finalize already called");var e=U(t);t=e[0];for(var r,n,i=e[1],s=0,a=t.length,h=this.blocks,o=this.buffer8;s<a;){if(this.hashed&&(this.hashed=!1,h[0]=h[16],h[16]=h[1]=h[2]=h[3]=h[4]=h[5]=h[6]=h[7]=h[8]=h[9]=h[10]=h[11]=h[12]=h[13]=h[14]=h[15]=0),i)if(p)for(n=this.start;s<a&&n<64;++s)(r=t.charCodeAt(s))<128?o[n++]=r:r<2048?(o[n++]=192|r>>>6,o[n++]=128|63&r):r<55296||r>=57344?(o[n++]=224|r>>>12,o[n++]=128|r>>>6&63,o[n++]=128|63&r):(r=65536+((1023&r)<<10|1023&t.charCodeAt(++s)),o[n++]=240|r>>>18,o[n++]=128|r>>>12&63,o[n++]=128|r>>>6&63,o[n++]=128|63&r);else for(n=this.start;s<a&&n<64;++s)(r=t.charCodeAt(s))<128?h[n>>>2]|=r<<A[3&n++]:r<2048?(h[n>>>2]|=(192|r>>>6)<<A[3&n++],h[n>>>2]|=(128|63&r)<<A[3&n++]):r<55296||r>=57344?(h[n>>>2]|=(224|r>>>12)<<A[3&n++],h[n>>>2]|=(128|r>>>6&63)<<A[3&n++],h[n>>>2]|=(128|63&r)<<A[3&n++]):(r=65536+((1023&r)<<10|1023&t.charCodeAt(++s)),h[n>>>2]|=(240|r>>>18)<<A[3&n++],h[n>>>2]|=(128|r>>>12&63)<<A[3&n++],h[n>>>2]|=(128|r>>>6&63)<<A[3&n++],h[n>>>2]|=(128|63&r)<<A[3&n++]);else if(p)for(n=this.start;s<a&&n<64;++s)o[n++]=t[s];else for(n=this.start;s<a&&n<64;++s)h[n>>>2]|=t[s]<<A[3&n++];this.lastByteIndex=n,this.bytes+=n-this.start,n>=64?(this.start=n-64,this.hash(),this.hashed=!0):this.start=n}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296|0,this.bytes=this.bytes%4294967296),this},K.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,e=this.lastByteIndex;t[e>>>2]|=w[3&e],e>=56&&(this.hashed||this.hash(),t[0]=t[16],t[16]=t[1]=t[2]=t[3]=t[4]=t[5]=t[6]=t[7]=t[8]=t[9]=t[10]=t[11]=t[12]=t[13]=t[14]=t[15]=0),t[14]=this.bytes<<3,t[15]=this.hBytes<<3|this.bytes>>>29,this.hash()}},K.prototype.hash=function(){var t,e,r,n,i,s,a=this.blocks;this.first?e=((e=((t=((t=a[0]-680876937)<<7|t>>>25)-271733879|0)^(r=((r=(-271733879^(n=((n=(-1732584194^2004318071&t)+a[1]-117830708)<<12|n>>>20)+t|0)&(-271733879^t))+a[2]-1126478375)<<17|r>>>15)+n|0)&(n^t))+a[3]-1316259209)<<22|e>>>10)+r|0:(t=this.h0,e=this.h1,r=this.h2,e=((e+=((t=((t+=((n=this.h3)^e&(r^n))+a[0]-680876936)<<7|t>>>25)+e|0)^(r=((r+=(e^(n=((n+=(r^t&(e^r))+a[1]-389564586)<<12|n>>>20)+t|0)&(t^e))+a[2]+606105819)<<17|r>>>15)+n|0)&(n^t))+a[3]-1044525330)<<22|e>>>10)+r|0),e=((e+=((t=((t+=(n^e&(r^n))+a[4]-176418897)<<7|t>>>25)+e|0)^(r=((r+=(e^(n=((n+=(r^t&(e^r))+a[5]+1200080426)<<12|n>>>20)+t|0)&(t^e))+a[6]-1473231341)<<17|r>>>15)+n|0)&(n^t))+a[7]-45705983)<<22|e>>>10)+r|0,e=((e+=((t=((t+=(n^e&(r^n))+a[8]+1770035416)<<7|t>>>25)+e|0)^(r=((r+=(e^(n=((n+=(r^t&(e^r))+a[9]-1958414417)<<12|n>>>20)+t|0)&(t^e))+a[10]-42063)<<17|r>>>15)+n|0)&(n^t))+a[11]-1990404162)<<22|e>>>10)+r|0,e=((e+=((t=((t+=(n^e&(r^n))+a[12]+1804603682)<<7|t>>>25)+e|0)^(r=((r+=(e^(n=((n+=(r^t&(e^r))+a[13]-40341101)<<12|n>>>20)+t|0)&(t^e))+a[14]-1502002290)<<17|r>>>15)+n|0)&(n^t))+a[15]+1236535329)<<22|e>>>10)+r|0,e=((e+=((n=((n+=(e^r&((t=((t+=(r^n&(e^r))+a[1]-165796510)<<5|t>>>27)+e|0)^e))+a[6]-1069501632)<<9|n>>>23)+t|0)^t&((r=((r+=(t^e&(n^t))+a[11]+643717713)<<14|r>>>18)+n|0)^n))+a[0]-373897302)<<20|e>>>12)+r|0,e=((e+=((n=((n+=(e^r&((t=((t+=(r^n&(e^r))+a[5]-701558691)<<5|t>>>27)+e|0)^e))+a[10]+38016083)<<9|n>>>23)+t|0)^t&((r=((r+=(t^e&(n^t))+a[15]-660478335)<<14|r>>>18)+n|0)^n))+a[4]-405537848)<<20|e>>>12)+r|0,e=((e+=((n=((n+=(e^r&((t=((t+=(r^n&(e^r))+a[9]+568446438)<<5|t>>>27)+e|0)^e))+a[14]-1019803690)<<9|n>>>23)+t|0)^t&((r=((r+=(t^e&(n^t))+a[3]-187363961)<<14|r>>>18)+n|0)^n))+a[8]+1163531501)<<20|e>>>12)+r|0,e=((e+=((n=((n+=(e^r&((t=((t+=(r^n&(e^r))+a[13]-1444681467)<<5|t>>>27)+e|0)^e))+a[2]-51403784)<<9|n>>>23)+t|0)^t&((r=((r+=(t^e&(n^t))+a[7]+1735328473)<<14|r>>>18)+n|0)^n))+a[12]-1926607734)<<20|e>>>12)+r|0,e=((e+=((s=(n=((n+=((i=e^r)^(t=((t+=(i^n)+a[5]-378558)<<4|t>>>28)+e|0))+a[8]-2022574463)<<11|n>>>21)+t|0)^t)^(r=((r+=(s^e)+a[11]+1839030562)<<16|r>>>16)+n|0))+a[14]-35309556)<<23|e>>>9)+r|0,e=((e+=((s=(n=((n+=((i=e^r)^(t=((t+=(i^n)+a[1]-1530992060)<<4|t>>>28)+e|0))+a[4]+1272893353)<<11|n>>>21)+t|0)^t)^(r=((r+=(s^e)+a[7]-155497632)<<16|r>>>16)+n|0))+a[10]-1094730640)<<23|e>>>9)+r|0,e=((e+=((s=(n=((n+=((i=e^r)^(t=((t+=(i^n)+a[13]+681279174)<<4|t>>>28)+e|0))+a[0]-358537222)<<11|n>>>21)+t|0)^t)^(r=((r+=(s^e)+a[3]-722521979)<<16|r>>>16)+n|0))+a[6]+76029189)<<23|e>>>9)+r|0,e=((e+=((s=(n=((n+=((i=e^r)^(t=((t+=(i^n)+a[9]-640364487)<<4|t>>>28)+e|0))+a[12]-421815835)<<11|n>>>21)+t|0)^t)^(r=((r+=(s^e)+a[15]+530742520)<<16|r>>>16)+n|0))+a[2]-995338651)<<23|e>>>9)+r|0,e=((e+=((n=((n+=(e^((t=((t+=(r^(e|~n))+a[0]-198630844)<<6|t>>>26)+e|0)|~r))+a[7]+1126891415)<<10|n>>>22)+t|0)^((r=((r+=(t^(n|~e))+a[14]-1416354905)<<15|r>>>17)+n|0)|~t))+a[5]-57434055)<<21|e>>>11)+r|0,e=((e+=((n=((n+=(e^((t=((t+=(r^(e|~n))+a[12]+1700485571)<<6|t>>>26)+e|0)|~r))+a[3]-1894986606)<<10|n>>>22)+t|0)^((r=((r+=(t^(n|~e))+a[10]-1051523)<<15|r>>>17)+n|0)|~t))+a[1]-2054922799)<<21|e>>>11)+r|0,e=((e+=((n=((n+=(e^((t=((t+=(r^(e|~n))+a[8]+1873313359)<<6|t>>>26)+e|0)|~r))+a[15]-30611744)<<10|n>>>22)+t|0)^((r=((r+=(t^(n|~e))+a[6]-1560198380)<<15|r>>>17)+n|0)|~t))+a[13]+1309151649)<<21|e>>>11)+r|0,e=((e+=((n=((n+=(e^((t=((t+=(r^(e|~n))+a[4]-145523070)<<6|t>>>26)+e|0)|~r))+a[11]-1120210379)<<10|n>>>22)+t|0)^((r=((r+=(t^(n|~e))+a[2]+718787259)<<15|r>>>17)+n|0)|~t))+a[9]-343485551)<<21|e>>>11)+r|0,this.first?(this.h0=t+1732584193|0,this.h1=e-271733879|0,this.h2=r-1732584194|0,this.h3=n+271733878|0,this.first=!1):(this.h0=this.h0+t|0,this.h1=this.h1+e|0,this.h2=this.h2+r|0,this.h3=this.h3+n|0)},K.prototype.hex=function(){this.finalize();var t=this.h0,e=this.h1,r=this.h2,n=this.h3;return d[t>>>4&15]+d[15&t]+d[t>>>12&15]+d[t>>>8&15]+d[t>>>20&15]+d[t>>>16&15]+d[t>>>28&15]+d[t>>>24&15]+d[e>>>4&15]+d[15&e]+d[e>>>12&15]+d[e>>>8&15]+d[e>>>20&15]+d[e>>>16&15]+d[e>>>28&15]+d[e>>>24&15]+d[r>>>4&15]+d[15&r]+d[r>>>12&15]+d[r>>>8&15]+d[r>>>20&15]+d[r>>>16&15]+d[r>>>28&15]+d[r>>>24&15]+d[n>>>4&15]+d[15&n]+d[n>>>12&15]+d[n>>>8&15]+d[n>>>20&15]+d[n>>>16&15]+d[n>>>28&15]+d[n>>>24&15]},K.prototype.toString=K.prototype.hex,K.prototype.digest=function(){this.finalize();var t=this.h0,e=this.h1,r=this.h2,n=this.h3;return[255&t,t>>>8&255,t>>>16&255,t>>>24&255,255&e,e>>>8&255,e>>>16&255,e>>>24&255,255&r,r>>>8&255,r>>>16&255,r>>>24&255,255&n,n>>>8&255,n>>>16&255,n>>>24&255]},K.prototype.array=K.prototype.digest,K.prototype.arrayBuffer=function(){this.finalize();var t=new ArrayBuffer(16),e=new Uint32Array(t);return e[0]=this.h0,e[1]=this.h1,e[2]=this.h2,e[3]=this.h3,t},K.prototype.buffer=K.prototype.arrayBuffer,K.prototype.base64=function(){for(var t,e,r,n="",i=this.array(),s=0;s<15;)t=i[s++],e=i[s++],r=i[s++],n+=b[t>>>2]+b[63&(t<<4|e>>>4)]+b[63&(e<<2|r>>>6)]+b[63&r];return t=i[s],n+=b[t>>>2]+b[t<<4&63]+"=="},S.prototype=new K,S.prototype.finalize=function(){if(K.prototype.finalize.call(this),this.inner){this.inner=!1;var t=this.array();K.call(this,this.sharedMemory),this.update(this.oKeyPad),this.update(t),K.prototype.finalize.call(this)}};const E=function(){var t=x("hex");t.create=function(){return new K},t.update=function(e){return t.create().update(e)};for(var e=0;e<g.length;++e){var r=g[e];t[r]=x(r)}return t}();async function z(e,r){e=t(e);let n=new Uint8Array(0),i=new Uint8Array(0);for(;n.length<48;){i=k(M(i,e,r)),n=M(n,i)}const s=n.slice(0,32),a=n.slice(32,48);return{key:await crypto.subtle.importKey("raw",s,"AES-CBC",!1,["encrypt","decrypt"]),iv:a}}function k(t){const e=t instanceof Uint8Array?Buffer.from(t):t,r=E(e);return new Uint8Array(Buffer.from(r,"hex"))}function M(...t){const e=t.reduce((t,e)=>t+e.length,0),r=new Uint8Array(e);let n=0;for(const e of t)r.set(e,n),n+=e.length;return r}const G=y,H=f;exports.decrypt=H,exports.decryptCbc=async function(t,e){return a(n(t),e)},exports.decryptCbcBin=a,exports.decryptGcm=f,exports.decryptGcmBin=c,exports.decryptLegacy=async function(t,e){const r=n(t);if("Salted__"!==String.fromCharCode(...r.slice(0,8)))throw new Error("Invalid OpenSSL header");const i=r.slice(8,16),{key:s,iv:a}=await z(e,i);return new Uint8Array(await crypto.subtle.decrypt({name:"AES-CBC",iv:a},s,r.slice(16)))},exports.encrypt=G,exports.encryptCbc=async function(t,e){return r(await s(t,e))},exports.encryptCbcBin=s,exports.encryptGcm=y,exports.encryptGcmBin=o,exports.encryptLegacy=async function(n,i){const s=e(8),{key:a,iv:h}=await z(i,s),o=new Uint8Array(await crypto.subtle.encrypt({name:"AES-CBC",iv:h},a,t(n))),c=new Uint8Array(16+o.length);return c.set(t("Salted__")),c.set(s,8),c.set(o,16),r(c)};
2
2
  //# sourceMappingURL=aes-bridge.cjs.js.map