@dev_innovations_labs/dil-gcm-envelope
v1.0.4
Published
AES-256-GCM envelope helper (payload, iv, tag) — TypeScript SDK
Maintainers
Readme
@dev_innovations_labs/dil-gcm-envelope
A lightweight, secure AES-256-GCM encryption SDK for Node.js, React Native, and Browser environments.
Designed for apps that need to send fully encrypted API requests using the envelope format:
{
"payload": "<base64>",
"iv": "<base64>",
"tag": "<base64>"
}This SDK ensures secure client–server communication where no readable data is transmitted over the network, even before TLS.
🚀 Features
- 🔐 AES-256-GCM authenticated encryption
- 📦 Tiny TypeScript SDK
- 🌐 Works in Node.js, React Native, and Browsers
- 🎯 Envelope output compatible with encrypted backends
- 🔄 Deterministic decrypt → always returns original object
- 🔑 Built-in secure key generator
- ⚡ Rollup optimized: ESM & CJS builds included
Installation
npm install @dev_innovations_labs/dil-gcm-envelopeor
yarn add @dev_innovations_labs/dil-gcm-envelopeGenerate a Key
AES-256 requires a 32-byte (256-bit) symmetric key.
import { generateKey } from "@dev_innovations_labs/dil-gcm-envelope";
const apiKey = generateKey();
console.log(apiKey); // Base64 stringStore keys securely:
- Backend →
.env - React Native → Keychain / Keystore
- Browser → Never hardcode, inject via server
Node.js Example (Backend)
Encrypt data
import { encrypt } from "@dev_innovations_labs/dil-gcm-envelope";
const key = process.env.API_ENC_KEY;
const envelope = await encrypt({ message: "Hello Backend" }, key);
console.log(envelope);Decrypt data
import { decrypt } from "@dev_innovations_labs/dil-gcm-envelope";
const decrypted = await decrypt(envelope, key);
console.log(decrypted);Example: Encrypted Backend Route (Express)
app.post("/login", async (req, res) => {
const key = process.env.API_ENC_KEY;
const decryptedBody = await decrypt(req.body, key);
const response = await encrypt({ status: true, token: "abc123" }, key);
return res.json(response);
});React Native Example
import { encrypt, decrypt } from "@dev_innovations_labs/dil-gcm-envelope";
global.__API_ENC_KEY = "BASE64-YOUR-KEY";
(async () => {
const env = await encrypt({ phone: "+91..." }, global.__API_ENC_KEY);
const dec = await decrypt(env, global.__API_ENC_KEY);
})();Browser (WebCrypto) Example
import { webEncrypt, webDecrypt } from "@dev_innovations_labs/dil-gcm-envelope";
const encrypted = await webEncrypt({ name: "Dev" }, key);
const decrypted = await webDecrypt(encrypted, key);Full Encrypted API Flow
(Frontend → Backend → Frontend)
Security Best Practices
- Never hardcode API keys
- Rotate keys periodically
- Use HTTPS
- Do not log encrypted blobs in production
License
MIT © Dev Innovations Labs
