UNPKG

@moinuddin_shaikh/encryptiondecryption

Version:

A lightweight Node.js library for encrypting and decrypting data using AES-256-CBC with double-seed-based key generation.

94 lines (60 loc) 2.66 kB
# Double Seed Encryption Double Seed Encryption is a lightweight Node.js library for encrypting and decrypting data using the AES-256-CBC algorithm with a double-seed-based key generation approach. This ensures robust data security, making it suitable for a wide range of applications. ## Features Double-Seed Security: Combines two seeds to generate a strong encryption key. Data Type Support: Works with text, strings, and JSON objects. AES-256-CBC Encryption: Provides a secure and widely-used encryption algorithm. No External Dependencies: Uses the built-in Node.js crypto module. Simple API: Easy-to-use functions for encryption and decryption. ## Installation Install the package using NPM: ## bash npm install double-seed-encryption ## Usage Encrypting and Decrypting Text Data javascript const { encrypt, decrypt } = require('double-seed-encryption'); // Define seeds const seed1 = 'myFirstSeed'; const seed2 = 'mySecondSeed'; // Data to encrypt const textData = 'This is some sensitive information'; // Encrypt data const encryptedData = encrypt(textData, seed1, seed2); console.log('Encrypted Data:', encryptedData); // Decrypt data const decryptedData = decrypt(encryptedData, seed1, seed2); console.log('Decrypted Data:', decryptedData); ## Encrypting and Decrypting JSON Data javascript const jsonData = { username: 'testUser', permissions: ['read', 'write'] }; // Encrypt JSON object const encryptedJson = encrypt(jsonData, seed1, seed2); console.log('Encrypted JSON:', encryptedJson); // Decrypt JSON object const decryptedJson = decrypt(encryptedJson, seed1, seed2); console.log('Decrypted JSON:', decryptedJson); ## API Reference encrypt(data, seed1, seed2) data: The data to encrypt (string, text, or JSON object). seed1: The first seed used for key generation. seed2: The second seed used for key generation. Returns: An encrypted string in the format IV:EncryptedData. decrypt(encryptedData, seed1, seed2) encryptedData: The encrypted string in the format IV:EncryptedData. seed1: The first seed used during encryption. seed2: The second seed used during encryption. Returns: The original data (string or JSON object). ## Example Use Cases Secure API payloads with JSON data. Encrypt configuration files or sensitive application data. Protect user credentials during transmission. ## Testing Run tests to ensure everything works correctly: ## bash npm test ## Repository and Issues Repository: GitHub Issues: GitHub Issues ## License This project is licensed under the MIT License. See the LICENSE file for details.