-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-crypto.js
More file actions
31 lines (24 loc) · 961 Bytes
/
test-crypto.js
File metadata and controls
31 lines (24 loc) · 961 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { encrypt, decrypt } from './utils/crypto.js';
import dotenv from 'dotenv';
// Load environment variables from .env file
dotenv.config();
const runTest = () => {
console.log('--- Running Encryption/Decryption Test ---');
const originalPassword = 'my-super-secret-password-123!';
console.log('Original Text: ', originalPassword);
// 1. Encrypt the text
const encryptedData = encrypt(originalPassword);
console.log('Encrypted Hash: ', encryptedData);
// 2. Decrypt the hash
const decryptedPassword = decrypt(encryptedData);
console.log('Decrypted Text: ', decryptedPassword);
// 3. Verify the result
console.log('\n--- Verification ---');
const isMatch = originalPassword === decryptedPassword;
if (isMatch) {
console.log('✅ SUCCESS: Decrypted text matches the original.');
} else {
console.log('❌ FAILED: Decrypted text does not match the original.');
}
};
runTest();