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
Markdown
## π 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"
```