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.

34 lines (29 loc) 1.36 kB
const { encrypt, decrypt } = require('./index'); // Adjust path if needed describe('Double Seed Encryption-Decryption Tests', () => { const seed1 = 'firstSeed'; const seed2 = 'secondSeed'; const data = 'Test data'; test('Encryption and Decryption should work correctly', () => { const encryptedData = encrypt(data, seed1, seed2); const decryptedData = decrypt(encryptedData, seed1, seed2); expect(decryptedData).toBe(data); }); test('Decryption should fail with wrong seeds', () => { const encryptedData = encrypt(data, seed1, seed2); expect(() => decrypt(encryptedData, 'wrongSeed1', seed2)).toThrow(); expect(() => decrypt(encryptedData, seed1, 'wrongSeed2')).toThrow(); }); test('Encryption should produce different results each time', () => { const encryptedData1 = encrypt(data, seed1, seed2); const encryptedData2 = encrypt(data, seed1, seed2); expect(encryptedData1).not.toBe(encryptedData2); // IV makes the output unique }); test('Should handle JSON data correctly', () => { const data = { username: 'testuser', permissions: ['read', 'write'] }; const encrypted = encrypt(data, seed1, seed2); console.log(encrypted); const decrypted = decrypt(encrypted, seed1, seed2); console.log(decrypted); expect(decrypted).toEqual(data); }); });