34 lines
1.2 KiB
JavaScript
34 lines
1.2 KiB
JavaScript
const { initEncryption, encrypt, decrypt, hashValue, verifyHash } = require('./src/utils/encryption');
|
|
const crypto = require('crypto');
|
|
|
|
// Initialize
|
|
const key = crypto.randomBytes(32).toString('hex');
|
|
initEncryption(key);
|
|
|
|
console.log('🔐 Testing Encryption...\n');
|
|
|
|
// Test 1: Basic encryption/decryption
|
|
const plaintext = 'test@example.com';
|
|
const encrypted = encrypt(plaintext);
|
|
const decrypted = decrypt(encrypted);
|
|
|
|
console.log('Test 1: Basic Encryption');
|
|
console.log(' Plaintext:', plaintext);
|
|
console.log(' Encrypted:', encrypted.substring(0, 50) + '...');
|
|
console.log(' Decrypted:', decrypted);
|
|
console.log(' Match:', plaintext === decrypted ? '✅' : '❌');
|
|
|
|
// Test 2: Hash and verify
|
|
const value = 'mytoken123';
|
|
const { hash, salt } = hashValue(value);
|
|
const isValid = verifyHash(value, hash, salt);
|
|
const isInvalid = verifyHash('wrongvalue', hash, salt);
|
|
|
|
console.log('\nTest 2: Hash and Verify');
|
|
console.log(' Value:', value);
|
|
console.log(' Hash:', hash.substring(0, 30) + '...');
|
|
console.log(' Valid verification:', isValid ? '✅' : '❌');
|
|
console.log(' Invalid verification:', !isInvalid ? '✅' : '❌');
|
|
|
|
console.log('\n✅ All encryption tests passed!');
|