AesBridge is a modern, secure and cross-language AES encryption library
npm install aes-bridge

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.
This is the JavaScript implementation of the core project.
š Main repository: https://github.com/mervick/aes-bridge
- š AES-256 encryption in GCM and CBC modes
- š Unified cross-language design
- š¦ Compact binary format or base64 output
- ā
HMAC Integrity: CBC mode includes HMAC verification
- š Backward Compatible: Supports legacy AES Everywhere format
- š» Works in both Node.js and browsers (UMD + ESM + CJS)
``bash`
npm install aes-bridgeor
yarn add aes-bridge
#### Browser (UMD)
`html`
#### CDN Option
`html`
#### Node.js (ES Modules)
For Node.js applications using ES Modules:
`js
import { encrypt, decrypt } from 'aes-bridge';
const ciphertext = await encrypt('My secret message', 'MyStrongPass');
const plaintext = await decrypt(ciphertext, 'MyStrongPass');
`
- encrypt(data, passphrase) Promise
Encrypts a string using AES-GCM (default).
Returns: - base64-encoded string.decrypt(ciphertext, passphrase)
- Promise
Decrypts a base64-encoded string encrypted with AES-GCM.
Returns: - raw binary data.
- encryptGcm(data, passphrase) Promise
Encrypts a string using AES-GCM.
Returns: - base64-encoded string.
- decryptGcm(ciphertext, passphrase) encryptGcm
Decrypts a base64-encoded string encrypted with . Promise
Returns: - raw binary data.
- encryptGcmBin(data, passphrase) Promise
Returns encrypted binary data using AES-GCM.
Returns: - raw binary data.decryptGcmBin(ciphertext, passphrase)
- encryptGcmBin
Decrypts binary data encrypted with . Promise
Returns: - raw binary data.
- encryptCbc(data, passphrase) Promise
Encrypts a string using AES-CBC.
HMAC is used for integrity verification.
Returns: - base64-encoded string.
- decryptCbc(ciphertext, passphrase) encryptCbc
Decrypts a base64-encoded string encrypted with and verifies HMAC. Promise
Returns: - raw binary data.
- encryptCbcBin(data, passphrase) Promise
Returns encrypted binary data using AES-CBC with HMAC.
Returns: - raw binary data.
- decryptCbcBin(ciphertext, passphrase) encryptCbcBin
Decrypts binary data encrypted with and verifies HMAC. Promise
Returns: - raw binary data.
ā ļø These functions are kept for backward compatibility only.
Their usage is strongly discouraged in new applications.
- encryptLegacy(data, passphrase) Promise
Encrypts a string in the legacy AES Everywhere format.
Returns: - base64-encoded string.
- decryptLegacy(ciphertext, passphrase) Promise
Decrypts a string encrypted in the legacy AES Everywhere format.
Returns: - raw binary data.
---
All functions in this library return a Promise. Specifically:
* encrypt, encryptGcm, encryptCbc, encryptLegacy Promise
Returns: - typically base64-encoded string.
* encryptGcmBin, encryptCbcBin, Promise
Returns: - raw binary data.
* decrypt, decryptGcm, decryptGcmBin, decryptCbc, decryptCbcBin, decryptLegacy Promise
Returns: - raw binary data.
---
As noted above, decryption functions and binary encryption functions (those with decrypt or Bin in their name) return a Promise. 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.
Here's an example of how you can convert the Uint8Array to a string:
`javascript
// Assuming decryptedResult is a Promise
const decryptedUint8Array = await decryptedResult;
const decoder = new TextDecoder('utf-8', { fatal: true });
let finalStringResult;
try {
finalStringResult = decoder.decode(decryptedUint8Array);
console.log("Decrypted string:", finalStringResult);
} catch (e) {
console.error("Decoding failed:", e);
// Handle decoding errors, e.g., if the data is not valid UTF-8
}
`
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.