UNPKG

cryptia

Version:

Cryptia is a simple JavaScript library for encrypting and decrypting text using a basic substitution cipher. It provides an easy-to-use interface for securing text data in client-side applications..

149 lines (111 loc) β€’ 4.04 kB
## πŸ›  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: ```bash npm i cryptia ``` Or clone the GitHub repository: ```bash git clone https://github.com/chukwunonsoprosper/cryptia cd cryptia ``` ### Testing the Library To test the library, run: ```bash npm run test ``` ### Customizable Workspace To spin up a customizable workspace, run: ```bash npm run dev ``` You can also link `workspace.js` to your project directory to integrate CryptiaJS easily. ### Example ```javascript /** * 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 ```javascript // 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 ```bash npm install -g cryptia ``` ### CLI Examples ```bash # 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" ```