Back up imported WhatsApp session with AES-256-GCM encryption

#1
WHATSAPP-BACKUP.md ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Encrypted WhatsApp session backup
2
+
3
+ This is an AES-256-GCM encrypted snapshot of the WhatsApp authentication folder generated locally using the Baileys 7.0.0-rc14 library bundled with the official OpenClaw WhatsApp plugin 2026.10.3.
4
+
5
+ The recovery key is stored locally on the owner's computer as `whatsapp-backup-key.txt`. It is intentionally absent from this repository. Do not upload the key or a decrypted archive to a public repository.
6
+
7
+ Decrypt with Node.js:
8
+
9
+ ```sh
10
+ node decrypt-whatsapp-backup.mjs whatsapp-session.encrypted.json /private/path/whatsapp-backup-key.txt /private/path/whatsapp-session.tar.gz
11
+ ```
12
+
13
+ The decrypted archive contains `creds.json` and its companion session and key JSON files. For the default account, these belong in `/home/node/.openclaw/credentials/whatsapp/default/` on this Space. Stop the WhatsApp channel, preserve the existing account directory, restore the whole snapshot with directory mode 700 and file mode 600, then start the channel. Do not run the local and hosted copies of the same linked session at the same time.
14
+
15
+ The session was imported privately into the running Space and recognized as linked. At verification, the hosted channel still failed to connect with status 408. The encrypted repository snapshot is a recovery backup; it does not fix outbound connectivity or automatically restore at startup. Main-branch changes can rebuild this Space and discard ephemeral state, so this backup is kept in a pull request without changing the running deployment.
16
+
17
+ WhatsApp authentication state changes over time. This is a point-in-time snapshot; use current private persistent storage for long-term session continuity.
decrypt-whatsapp-backup.mjs ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import fs from 'node:fs/promises';
2
+ import { createDecipheriv } from 'node:crypto';
3
+ const [encryptedFile, keyFile, outputFile] = process.argv.slice(2);
4
+ if (!encryptedFile || !keyFile || !outputFile) {
5
+ throw new Error('Usage: node decrypt-whatsapp-backup.mjs ENCRYPTED_JSON PRIVATE_KEY_FILE OUTPUT_TAR_GZ');
6
+ }
7
+ const envelope = JSON.parse(await fs.readFile(encryptedFile, 'utf8'));
8
+ if (envelope.format !== 'openclaw-whatsapp-backup-v1' || envelope.algorithm !== 'aes-256-gcm') {
9
+ throw new Error('Unsupported backup format');
10
+ }
11
+ const key = Buffer.from((await fs.readFile(keyFile, 'utf8')).trim(), 'base64');
12
+ if (key.length !== 32) throw new Error('Recovery key must contain 32 bytes in base64');
13
+ const decipher = createDecipheriv('aes-256-gcm', key, Buffer.from(envelope.iv, 'base64'));
14
+ decipher.setAuthTag(Buffer.from(envelope.tag, 'base64'));
15
+ const plaintext = Buffer.concat([decipher.update(Buffer.from(envelope.ciphertext, 'base64')), decipher.final()]);
16
+ await fs.writeFile(outputFile, plaintext, { flag: 'wx', mode: 0o600 });
17
+ console.log('Decrypted authentication archive saved. Keep the archive and recovery key private.');
whatsapp-session.encrypted.json ADDED
The diff for this file is too large to render. See raw diff