@xcrap/decryptor
v0.1.0
Published
Powerful response decryption wrapper for @xcrap clients
Readme
@xcrap/decryptor
Powerful response decryption wrapper for @xcrap clients. Automatically decrypts encrypted HTTP response bodies using standard algorithms.
Features
- Automatic Decryption: Wraps any
@xcrapclient to decrypt responses on the fly. - Flexible Configuration: Supports multiple algorithms, encodings, and key/IV formats.
- Factory Pattern: Easy integration using the
DecryptorClientfactory. - Standard Crypto: Uses Node.js
node:cryptounder the hood.
Installation
npm install @xcrap/decryptorUsage
Using injectDecryptor
You can wrap an existing client instance to add decryption capabilities.
import { AxiosClient } from '@xcrap/axios-client';
import { injectDecryptor } from '@xcrap/decryptor';
const baseClient = new AxiosClient();
const client = injectDecryptor(baseClient, {
algorithm: 'aes-256-cbc',
inputEncoding: 'base64',
outputEncoding: 'utf8',
key: { encoding: 'utf8', value: 'your-32-character-secret-key-!!' },
iv: { encoding: 'utf8', value: 'your-16-char-iv!' }
});
// All fetch and fetchMany calls will now automatically decrypt the response body
const response = await client.fetch({ url: '...' });
console.log(response.body); // Decrypted contentUsing DecryptorClient Factory
Perfect for class-based architectures.
import { AxiosClient } from '@xcrap/axios-client';
import { DecryptorClient } from '@xcrap/decryptor';
const DecryptedAxios = DecryptorClient(AxiosClient, {
algorithm: 'aes-256-cbc',
inputEncoding: 'base64',
outputEncoding: 'utf8',
key: { encoding: 'hex', value: '...' },
iv: { encoding: 'hex', value: '...' }
});
const client = new DecryptedAxios();Configuration
The DecryptConfig object supports:
| Field | Type | Description |
|-------|------|-------------|
| algorithm | string | Crypto algorithm (e.g., aes-256-cbc) |
| inputEncoding | BufferEncoding | Encoding of the encrypted response body |
| outputEncoding | BufferEncoding | Desired encoding for the decrypted result |
| key | Object | { encoding, value } for the secret key |
| iv | Object | { encoding, value } for the initialization vector |
License
MIT © Marcuth
