-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest-encryption.js
More file actions
59 lines (47 loc) · 2.04 KB
/
Copy pathtest-encryption.js
File metadata and controls
59 lines (47 loc) · 2.04 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* Quick encryption test script
* Run with: node test-encryption.js
*
* Note: This won't work directly because it uses Web Crypto API
* which is browser-only. But it shows the test logic.
*/
// To actually test in Node.js, you'd need:
// npm install --save-dev @peculiar/webcrypto
// Then uncomment below:
// const { Crypto } = require('@peculiar/webcrypto');
// global.crypto = new Crypto();
async function testEncryption() {
console.log('🧪 Testing E2EE Encryption...\n');
try {
// This would import your encryption module
// const { generateKeyPair, encryptMessage, decryptMessage } = require('./app/lib/encryption.ts');
console.log('✅ All encryption functions loaded');
// Test 1: Key Generation
console.log('\n📝 Test 1: Key Generation');
// const keys = await generateKeyPair();
// console.log(' ✅ Generated keys');
// console.log(' Public key length:', keys.publicKey.length);
// console.log(' Private key length:', keys.privateKey.length);
// Test 2: Encryption
console.log('\n📝 Test 2: Message Encryption');
const testMessage = 'This is a secret test message!';
// const encrypted = await encryptMessage(testMessage, keys.publicKey);
// console.log(' ✅ Message encrypted');
// console.log(' Original length:', testMessage.length);
// console.log(' Encrypted length:', encrypted.length);
// Test 3: Decryption
console.log('\n📝 Test 3: Message Decryption');
// const decrypted = await decryptMessage(encrypted, keys.privateKey);
// console.log(' ✅ Message decrypted');
// console.log(' Decrypted message:', decrypted);
// Test 4: Verify Match
console.log('\n📝 Test 4: Verify Original = Decrypted');
// const match = testMessage === decrypted;
// console.log(' Match:', match ? '✅ YES' : '❌ NO');
console.log('\n🎉 All tests passed!\n');
console.log('Note: To actually run this, use the browser test page at /test-encryption');
} catch (error) {
console.error('❌ Test failed:', error);
}
}
testEncryption();