This package provides encryption and decryption utilities for Baileys sessions. The code allows you to securely encrypt session data and later decrypt it back to its original state.
- Encrypt Baileys session: Encrypt your session credentials and synchronization data into a single encrypted file.
- Decrypt Baileys session: Decrypt the encrypted session back into its original JSON files (
creds.json
andapp-state-sync-key-{appStateKeyId}.json
).
Before using this tool, make sure you have the session files generated from Baileys. You need the following:
creds.json
(session credentials file)app-state-sync-key-{appStateKeyId}.json
(sync key file)
To use the package, you need Node.js (version 14 or higher) installed. You can install the required dependencies via:
npm install baileys
Or with Yarn:
yarn install baileys
To encrypt your Baileys session, use the encryptSession
function. It merges your session and sync key data, then encrypts the combined data using AES-256-CBC.
import { encryptSession } from './sessionEncryptor';
const encryptedSession = encryptSession('path/to/creds.json');
console.log('Encrypted session data:', encryptedSession);
The encrypted session is saved to a file named session.json
in your current working directory.
To decrypt a previously encrypted session, use the decryptSession
function. It restores the original creds.json
and sync key files.
import { decryptSession } from './sessionEncryptor';
const sessionData = decryptSession('path/to/session.json', './outputDir');
console.log('Decrypted session data:', sessionData);
The decrypted session files will be saved in the specified output directory (defaults to ./session
).
This function:
- Reads the session and sync key files.
- Merges the session data and sync key.
- Encrypts the merged data using AES-256-CBC.
- Saves the encrypted session as
session.json
.
This function:
- Reads the encrypted session from the provided file.
- Decrypts the data using the key and IV from the encrypted file.
- Restores the original
creds.json
and sync key files into the specified output directory.
import { encryptSession, decryptSession } from './sessionEncryptor';
// Encrypt session
const encryptedSession = encryptSession('path/to/creds.json');
console.log('Encrypted session data:', encryptedSession);
// Decrypt session
const decryptedSession = decryptSession('path/to/session.json', './decryptedSession');
console.log('Decrypted session data:', decryptedSession);
node:fs
(for file operations)node:crypto
(for encryption and decryption)node:path
(for path manipulations)