Fix database setup, test encryption and repositories - all working
Co-authored-by: southseact-3d <217551146+southseact-3d@users.noreply.github.com>
This commit is contained in:
33
chat/test-encryption.js
Normal file
33
chat/test-encryption.js
Normal file
@@ -0,0 +1,33 @@
|
||||
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!');
|
||||
Reference in New Issue
Block a user