secury
v1.0.1
Published
AES-256-GCM encryption utility with Express middleware support for secure data transmission
Downloads
216
Maintainers
Readme
secury
AES-256-GCM encryption utility with Express middleware support for secure data transmission.
Features
- AES-256-GCM Encryption: Authenticated encryption with associated data (AEAD)
- Flexible Key Handling: Support for string keys, buffers, or auto-generated keys
- Express Middleware: Built-in middleware for decrypting request bodies
- Basic Auth Middleware: Simple token-based authorization
- Zero Dependencies: Uses only Node.js built-in
cryptomodule
Installation
npm install secury
import secury from 'secury';
// Create AES handler with a string key
const aes = secury.aes('my-secret-key');
// Encrypt data
const encrypted = aes.encrypt('Hello, World!');
console.log(encrypted); // Base64 encoded string
// Decrypt data
const decrypted = aes.decrypt(encrypted);
console.log(decrypted); // 'Hello, World!'
import secury from 'secury';
// Generate a random 32-byte key
const aes = secury.aes(32);
// Get the generated key
const key = aes.aesKey();
console.log(key.toString('hex'));
// Renew the key
const newKey = aes.renew();
import express from 'express';
import secury from 'secury';
const app = express();
const aes = secury.aes('your-secret-key');
// Decrypt incoming requests
app.post('/secure', aes.authRoute(), (req, res) => {
// req.body is automatically decrypted and parsed as JSON
console.log(req.body);
res.json({ success: true });
});
import express from 'express';
import secury from 'secury';
const app = express();
// Protect routes with a secret token
app.use('/admin', secury.basicAuthor('my-secret-token', { error: 'Unauthorized' }), (req, res) => {
res.json({ message: 'Admin access granted' });
});