Skip to content
xcrap-devPublic

Latest commit

 

History

8 Commits

Folders and files

Repository files navigation

@xcrap/decryptor

Powerful response decryption wrapper for @xcrap clients. Automatically decrypts encrypted HTTP response bodies using standard algorithms.

Features

  • Automatic Decryption: Wraps any @xcrap client to decrypt responses on the fly.
  • Flexible Configuration: Supports multiple algorithms, encodings, and key/IV formats.
  • Factory Pattern: Easy integration using the DecryptorClient factory.
  • Standard Crypto: Uses Node.js node:crypto under the hood.

Installation

npm install @xcrap/decryptor

Usage

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 content

Using 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

Releases

Packages

Contributors

Languages