OpenClaw Quantum-Safe Crypto Skill
Overview
This skill provides quantum-safe data and file encryption/decryption capabilities via the OpenClaw plugin (quantum_crypto.cjs).
Setup
- Copy the entire
skill/directory to the target project - Fill in
quantum.jsonwith valid credentials - Use
require('./skill/quantum_crypto.cjs')to load the plugin
API
init() - Initialize
Must be called first. Resolves KMS address, pulls fill-keys, logs into KMS.
encrypt(plainText, mode) -> { cipherText, keyId }
Encrypt a string.
decrypt(cipherText, keyId, mode) -> { plainText }
Decrypt a string.
encryptFile(fileData, mode, opts?) -> { fileBuffer, keyId, sessionKey, fillKey }
Encrypt a file Buffer. Pass { keyId, sessionKey, fillKey } from previous call to reuse session key across chunks.
decryptFile(fileData, keyId, mode, opts?) -> { fileBuffer, sessionKey, fillKey }
Decrypt a file Buffer. Pass { sessionKey, fillKey } from previous call to reuse keys across chunks.
Encryption Modes
| Mode | Algorithm |
|---|---|
| 1 | SM4_ECB_NOPADDING |
| 2 | SM4_ECB_PKCS7PADDING |
| 3 | SM4_CBC_NOPADDING |
| 4 | SM4_CBC_PKCS7PADDING |
Usage Example
const qsEncryptPlug = require('./skill/quantum_crypto.cjs');
// Initialize
await qsEncryptPlug.init();
// String encrypt/decrypt
const { cipherText, keyId } = await qsEncryptPlug.encrypt('Hello', 2);
const { plainText } = await qsEncryptPlug.decrypt(cipherText, keyId, 2);
// File encrypt (chunked, 10MB per chunk)
const CHUNK = 10 * 1024 * 1024;
let sessionKey, fillKey, keyId;
for (let i = 0; i < fileSize; i += CHUNK) {
const chunk = readChunk(filePath, i, CHUNK);
const r = await qsEncryptPlug.encryptFile(chunk, 1, { keyId, sessionKey, fillKey });
keyId = r.keyId; sessionKey = r.sessionKey; fillKey = r.fillKey;
writeChunk(r.fileBuffer, outStream);
}
// File decrypt (10MB + 16 per chunk)
const D_CHUNK = CHUNK + 16;
let dSk, dFk;
for (let i = 0; i < encFileSize; i += D_CHUNK) {
const chunk = readChunk(encPath, i, D_CHUNK);
const r = await qsEncryptPlug.decryptFile(chunk, keyId, 1, { sessionKey: dSk, fillKey: dFk });
dSk = r.sessionKey; dFk = r.fillKey;
writeChunk(r.fileBuffer, outStream);
}
File Structure
skill/
├── quantum_crypto.cjs # Plugin (minified)
├── libqss_common.wasm # WASM crypto module
├── quantum.json # Configuration (fill before use)
├── SKILL.md # Qoder skill definition
└── README.md # Usage documentation
