Dgcrypt is a simple Node.js library for encryption and decryption using various encryption methods, including AES-256-CBC, AES-256-GCM, and ChaCha20-Poly1305. It is designed to securely encrypt data on the backend, which can then be easily decrypted on the client side, such as on Android, iOS, and other platforms. This ensures that the data remains secure during transmission and cannot be easily cracked in between.
The Dgcrypt library is designed to work seamlessly across multiple platforms. You can find corresponding libraries for the following platforms:
- Android: Dgcrypt-Android
- PHP: Dgcrypt-PHP
These libraries allow you to easily decrypt data that was encrypted on the backend using this PHP library, ensuring secure communication between your backend and client applications.
Dgcrypt supports the following encryption methods:
- AES-256-CBC: Standard encryption method providing confidentiality.
- AES-256-GCM: Provides both encryption and authentication.
- ChaCha20-Poly1305: Modern encryption method known for its performance and security.
You can install the package via npm, available for Node.js v16 and above:
npm install @davodm/dgcrypt-node
const Dgcrypt = require('@davodm/dgcrypt-node');
const dgcrypt = new Dgcrypt('aes-256-cbc'); // Specify the encryption method
const secretKey = 'your-secret-key';
const data = 'Hello, World!';
const encryptedData = dgcrypt.encrypt(data, secretKey);
console.log('Encrypted Data:', encryptedData);
const Dgcrypt = require('@davodm/dgcrypt-node');
const dgcrypt = new Dgcrypt('aes-256-cbc'); // Specify the encryption method
const secretKey = 'your-secret-key';
const encryptedData = 'your-encrypted-data';
const decryptedData = dgcrypt.setCipherMethod('aes-256-cbc').decrypt(encryptedData, secretKey);
console.log('Decrypted Data:', decryptedData);
const Dgcrypt = require('@davodm/dgcrypt-node');
const dgcrypt = new Dgcrypt();
const generatedKey = dgcrypt.generateKey();
console.log('Generated Key:', generatedKey); // Display the key in hexadecimal format
To run the tests, use Jest:
npm test
This project is licensed under the MIT License - see the LICENSE file for details.
Davod Mozafari - Twitter