🛠 Usage
CryptiaJS 🔐 CryptiaJS is a powerful and secure JavaScript library for encrypting and decrypting text and files using advanced encryption algorithms. Whether you're safeguarding sensitive data in web applications or adding encryption to your server-side projects, CryptiaJS is designed to be fast, reliable, and easy to use. ⚡
Your data stays protected—as long as you keep your encryption key private.
🚀 Installation
Install CryptiaJS via npm:
npm i cryptia
Or clone the GitHub repository:
git clone https://github.com/chukwunonsoprosper/cryptia
cd cryptia
Testing the Library
To test the library, run:
npm run test
Customizable Workspace
To spin up a customizable workspace, run:
npm run dev
You can also link workspace.js
to your project directory to integrate CryptiaJS easily.
Example
/**
* Import Cryptia and required dependencies.
*/
import Cryptia from '../cryptia.js'
// Initialize Cryptia with custom settings.
const cryptia = Cryptia({
obfuscationLevel: 10,
logging: false,
preserveWhitespace: true
});
/**
* Encrypt and decrypt text with a secure key.
*/
const plainText = 'This is a secret message.🤣😂';
const encryptionKey = 'MySecureKey1';
const encryptedResult = cryptia.encrypt(plainText, encryptionKey)
console.log('Encrypted Text:', encryptedResult.data);
const decryptedResult = cryptia.decrypt(encryptedResult.data, encryptionKey)
console.log('Decrypted Text:', decryptedResult.data);
// Encrypt a file
const fileEncryptResult = cryptia.encryptFile(
'/path/to/file.txt',
'secretKey',
null, // Callback function (optional)
'output.encrypted' // Output filename (optional)
);
console.log(`File encrypted to: ${fileEncryptResult.encryptedFilePath}`);
// Decrypt a file
const fileDecryptResult = cryptia.decryptFile(
'output.encrypted',
'secretKey',
null, // Callback function (optional)
'decrypted_output.txt' // Output filename (optional)
);
console.log(`File decrypted to: ${fileDecryptResult.decryptedFilePath}`);
🔥 What's New in v1.0.6?
- ✅ Binary Data Encryption - Support for images, PDFs and other binary files
- ✅ Large File Streaming - Process large files without memory limitations
- ✅ Progress Tracking - Monitor encryption/decryption progress in real-time
- ✅ Key Strength Verification - Built-in security checks for encryption keys
- ✅ Command Line Interface - Encrypt/decrypt directly from the terminal
- ✅ Stronger security – Your encrypted data stays safe as long as your encryption key remains private
- ✅ Better performance – Optimized for speed and efficiency
- ✅ Cleaner code – More maintainable and readable
- ✅ Improved documentation – Making integration smoother than ever
Binary Data Encryption
// Encrypt binary data (like an image)
const imageBuffer = fs.readFileSync('image.png');
const encryptedBinary = cryptia.encryptBinary(imageBuffer, 'secretKey');
fs.writeFileSync('encrypted.bin', encryptedBinary.data);
// Decrypt binary data
const encryptedData = fs.readFileSync('encrypted.bin', 'utf-8');
const decryptedBinary = cryptia.decryptBinary(encryptedData, 'secretKey');
fs.writeFileSync('decrypted.png', decryptedBinary.data);
// Encrypt a large file using streams
await cryptia.encryptLargeFile(
'/path/to/large-file.mp4',
'/path/to/output-encrypted.bin',
'secretKey'
);
// Decrypt a large file using streams
await cryptia.decryptLargeFile(
'/path/to/output-encrypted.bin',
'/path/to/recovered-file.mp4',
'secretKey'
);
Install CLI globally
npm install -g cryptia
CLI Examples
# Encrypt text
cryptia encrypt --text "Secret message" --key "mySecretKey"
# Decrypt text
cryptia decrypt --text "ENCRYPTED_TEXT" --key "mySecretKey"
# Encrypt file
cryptia encrypt --file "/path/to/file.txt" --key "mySecretKey"
# Decrypt file
cryptia decrypt --file "/path/to/file.encrypted" --key "mySecretKey"