Central API for all GhostCrypt operations (encrypt, decrypt, keyfile generation).
await ghost(options)
await ghost('upload') // File upload
await ghost('upload', 'keyfile') // Keyfile upload
await ghost('download') // Download .ghost
await ghost('download', 'keyfile') // Download .gkey
await ghost('reset') // Reset cache{
action: 'encrypt' | 'decrypt', // Required
file: File | ArrayBuffer, // Required
keyMethod: 'password' | 'keyfile',// Required
password: String, // If keyMethod='password'
keyfile: ArrayBuffer // If keyMethod='keyfile'
}const file = await ghost('upload');
await ghost({
action: 'encrypt',
file: file,
keyMethod: 'password',
password: 'MySecurePassword123'
});
ghost('download'); // .ghost fileconst file = await ghost('upload');
await ghost({
action: 'encrypt',
file: file,
keyMethod: 'keyfile'
// Keyfile auto-generated
});
ghost('download', 'ghost'); // .ghost file
ghost('download', 'keyfile'); // .gkey fileconst ghostFile = await ghost('upload');
await ghost({
action: 'decrypt',
file: ghostFile,
keyMethod: 'password',
password: 'MySecurePassword123'
});
ghost('download'); // Original fileconst ghostFile = await ghost('upload');
const keyfile = await ghost('upload', 'keyfile');
await ghost({
action: 'decrypt',
file: ghostFile,
keyMethod: 'keyfile',
keyfile: keyfile.content // ArrayBuffer
});
ghost('download'); // Original fileconst textData = 'Secret message';
await ghost({
action: 'encrypt',
file: textData,
keyMethod: 'password',
password: 'password123'
});
ghost('download'); // .ghost file// Regular file upload
const file = await ghost('upload');
// Returns: { name, type, size, lastModified, content: ArrayBuffer }
// Keyfile upload (.gkey)
const keyfile = await ghost('upload', 'keyfile');
// Returns: { name, type, size, lastModified, content: ArrayBuffer }// Download encrypted file
ghost('download');
// Download keyfile
ghost('download', 'keyfile');// Clear all cached data
ghost('reset');
// Returns: { success: true, action: 'reset', message: 'Cache cleared' }{
success: true,
action: 'encrypt',
return: ArrayBuffer, // .ghost file
keyfile: Uint8Array // Only if keyMethod='keyfile'
}{
success: true,
action: 'decrypt',
return: ArrayBuffer // Original file
}{
success: false,
action: 'encrypt' | 'decrypt',
error: 'Error message'
}<script src="ghostcrypt-v1/ghostcrypt-v1-bundle.min.js"></script><script src="ghostcrypt-dependencies/argon2.min.js"></script>
<script src="ghostcrypt-dependencies/crypto-js.min.js"></script>
<script src="ghostcrypt-dependencies/chacha20.min.js"></script>
<script src="ghostcrypt-v1/ghostcrypt-v1.min.js"></script>- KDF: Argon2id (3 iter, 64 MB, 4 threads)
- Encryption: AES-256-CBC + ChaCha20
- Integrity: HMAC-SHA512 (64 bytes)
- Quantum: 128-bit resistance (~2040)
| File Size | Time | RAM |
|---|---|---|
| 1 MB | ~0.5s | ~5 MB |
| 10 MB | ~2s | ~20 MB |
| 100 MB | ~15s | ~200 MB |
| 1 GB | ~2m | ~2 GB |
Chrome 90+, Firefox 88+, Safari 14+, Edge 90+
try {
const file = await ghost('upload');
const result = await ghost({
action: 'encrypt',
file: file,
keyMethod: 'password',
password: 'password123'
});
if (result.success) {
ghost('download');
}
} catch (error) {
console.error('Encryption failed:', error);
}const files = await Promise.all([
ghost('upload'),
ghost('upload'),
ghost('upload')
]);
for (const file of files) {
await ghost({
action: 'encrypt',
file: file,
keyMethod: 'password',
password: 'password123'
});
ghost('download');
}"No file provided"→ Missing file parameter"Password is empty"→ Missing password with keyMethod='password'"Invalid keyfile format"→ Keyfile magic number/version invalid"HMAC verification failed"→ Wrong password/keyfile"Invalid .ghost file"→ File corrupted or wrong format
// ✅ Good
password: 'MyS3cur3P@ssw0rd!2024'
// ❌ Bad
password: 'password'
password: '12345678'// ✅ Store keyfile securely
const keyfile = await ghost('upload', 'keyfile');
// Save to offline storage (USB, external drive)
// ❌ Never
// - Email keyfiles
// - Upload to cloud without encryption
// - Store in same location as .ghost file<!DOCTYPE html>
<html>
<head>
<title>GhostCrypt Example</title>
<script src="ghostcrypt-v1/ghostcrypt-v1-bundle.min.js"></script>
</head>
<body>
<button onclick="encryptFile()">Encrypt File</button>
<button onclick="decryptFile()">Decrypt File</button>
<script>
async function encryptFile() {
try {
const file = await ghost('upload');
await ghost({
action: 'encrypt',
file: file,
keyMethod: 'password',
password: prompt('Enter password:')
});
ghost('download');
alert('✅ File encrypted!');
} catch (error) {
alert('❌ Error: ' + error.message);
}
}
async function decryptFile() {
try {
const file = await ghost('upload');
await ghost({
action: 'decrypt',
file: file,
keyMethod: 'password',
password: prompt('Enter password:')
});
ghost('download');
alert('✅ File decrypted!');
} catch (error) {
alert('❌ Error: ' + error.message);
}
}
</script>
</body>
</html>