https://github.com/theodoreai/crypto-tool
The following is a javascript module written to encrypt and decrypt JSON data using the Advanced Encryption Standard.
https://github.com/theodoreai/crypto-tool
Last synced: about 1 month ago
JSON representation
The following is a javascript module written to encrypt and decrypt JSON data using the Advanced Encryption Standard.
- Host: GitHub
- URL: https://github.com/theodoreai/crypto-tool
- Owner: TheodoreAI
- Created: 2023-03-02T05:59:31.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-18T20:05:46.000Z (about 3 years ago)
- Last Synced: 2025-07-11T16:40:00.761Z (11 months ago)
- Language: JavaScript
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CryptoTool - A Simple File Encryption and Decryption Tool
CryptoTool is a Node.js module for encrypting and decrypting files using the AES-256-CBC algorithm. It provides a simple object-oriented interface for handling encryption and decryption tasks.
## Installation
Place the cryptoTool.js file in your project directory.
## Usage
First, import the CryptoTool class from the cryptoTool.js file:
```javascript
const CryptoTool = require('./cryptoTool');
```
Next, create a new instance of the CryptoTool class with a custom initialization vector (IV) and secret key:
```javascript
const crypto = require('crypto');
const iv = crypto.randomBytes(16);
const key = crypto.randomBytes(32);
const initializationVector = Buffer.from(iv, 'hex');
const secretKey = Buffer.from(key, 'hex');
const cryptoTool = new CryptoTool(initializationVector, secretKey);
```
Use the cryptoTool instance to call the writeEncryptedMessage and writeDecryptedMessage methods, which will encrypt a file and decrypt the encrypted file, respectively:
```javascript
cryptoTool.writeEncryptedMessage("message.json");
cryptoTool.writeDecryptedMessage("encryptedMessage.json");
```
Additionally, you can use the encrypt and decrypt methods directly to encrypt and decrypt data:
```javascript
const encryptedData = cryptoTool.encrypt("message.json");
console.log("Encrypted data:", encryptedData);
const decryptedData = cryptoTool.decrypt(encryptedData);
console.log("Decrypted data:", decryptedData);
```
## Example
Here's a complete example of how to use the CryptoTool module:
```javascript
const CryptoTool = require('./cryptoTool');
// Create a new instance of the CryptoTool class with custom iv and key
const crypto = require('crypto');
const iv = crypto.randomBytes(16);
const key = crypto.randomBytes(32);
const initializationVector = Buffer.from(iv, 'hex');
const secretKey = Buffer.from(key, 'hex');
const cryptoTool = new CryptoTool(initializationVector, secretKey);
// Use the instance to call the methods
cryptoTool.writeEncryptedMessage("message.json");
cryptoTool.writeDecryptedMessage("encryptedMessage.json");
// You can also use the encrypt and decrypt methods directly if needed
const encryptedData = cryptoTool.encrypt("message.json");
console.log("Encrypted data:", encryptedData);
const decryptedData = cryptoTool.decrypt(encryptedData);
console.log("Decrypted data:", decryptedData);
```
## In Action
[decryptedJson]()
[encryptedJson]()
## License
This project is released under the MIT License.