-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_load.php
More file actions
131 lines (114 loc) · 4.38 KB
/
Copy pathtest_load.php
File metadata and controls
131 lines (114 loc) · 4.38 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/**
* CompleteOpenPGP Autoload & Verification Integration Test Script
* This script simulates loading the package via Composer autoload and runs
* a sanity check across all five cryptosystems (RSA, ElGamal, EdDSA, ECDSA, ECDH).
*/
require_once __DIR__ . '/vendor/autoload.php';
use KeyManagement\PGPKeyManager;
echo "===========================================\n";
echo "🧪 CompleteOpenPGP Autoload & Sanity Test\n";
echo "===========================================\n\n";
$testMessage = "Hello OpenPGP! Verification Successful.";
$allPassed = true;
// 1. RSA Verification
try {
echo "🔑 Testing RSA... ";
$keys = PGPKeyManager::generateKey('RSA');
$encrypted = PGPKeyManager::encrypt('RSA', $testMessage, $keys['public']);
$decrypted = PGPKeyManager::decrypt('RSA', $encrypted, $keys['private']);
$sig = PGPKeyManager::sign('RSA', $testMessage, $keys['private']);
$verified = PGPKeyManager::verify('RSA', $testMessage, $sig, $keys['public']);
if ($decrypted === $testMessage && $verified) {
echo "✅ RSA Passed\n";
} else {
throw new Exception("RSA decrypted or signature verification mismatch.");
}
} catch (Exception $e) {
echo "❌ RSA Failed: " . $e->getMessage() . "\n";
$allPassed = false;
}
// 2. ElGamal Verification
try {
echo "🔑 Testing ElGamal... ";
$keys = PGPKeyManager::generateKey('ElGamal');
$encrypted = PGPKeyManager::encrypt('ElGamal', $testMessage, $keys['public']);
$decrypted = PGPKeyManager::decrypt('ElGamal', $encrypted, $keys['private']);
if ($decrypted === $testMessage) {
echo "✅ ElGamal Passed\n";
} else {
throw new Exception("ElGamal decrypted mismatch.");
}
} catch (Exception $e) {
echo "❌ ElGamal Failed: " . $e->getMessage() . "\n";
$allPassed = false;
}
// 3. EdDSA Verification
try {
echo "🔑 Testing EdDSA (Ed25519)... ";
$keys = PGPKeyManager::generateKey('EdDSA');
$encrypted = PGPKeyManager::encrypt('EdDSA', $testMessage, $keys['public']);
$decrypted = PGPKeyManager::decrypt('EdDSA', $encrypted, $keys['private']);
$sig = PGPKeyManager::sign('EdDSA', $testMessage, $keys['private']);
$verified = PGPKeyManager::verify('EdDSA', $testMessage, $sig, $keys['public']);
if ($decrypted === $testMessage && $verified) {
echo "✅ EdDSA Passed\n";
} else {
throw new Exception("EdDSA decrypted or signature verification mismatch.");
}
} catch (Exception $e) {
echo "❌ EdDSA Failed: " . $e->getMessage() . "\n";
$allPassed = false;
}
// 4. ECDSA Verification
try {
echo "🔑 Testing ECDSA... ";
$keys = PGPKeyManager::generateKey('ECDSA');
$sig = PGPKeyManager::sign('ECDSA', $testMessage, $keys['private']);
$verified = PGPKeyManager::verify('ECDSA', $testMessage, $sig, $keys['public']);
if ($verified) {
echo "✅ ECDSA Passed\n";
} else {
throw new Exception("ECDSA signature verification mismatch.");
}
} catch (Exception $e) {
echo "❌ ECDSA Failed: " . $e->getMessage() . "\n";
$allPassed = false;
}
// 5. ECDH Verification
try {
echo "🔑 Testing ECDH (ECIES/AES-256-GCM)... ";
$keys = PGPKeyManager::generateKey('ECDH');
$encrypted = PGPKeyManager::encrypt('ECDH', $testMessage, $keys['public']);
$decrypted = PGPKeyManager::decrypt('ECDH', $encrypted, $keys['private']);
if ($decrypted === $testMessage) {
echo "✅ ECDH Passed\n";
} else {
throw new Exception("ECDH decrypted mismatch.");
}
} catch (Exception $e) {
echo "❌ ECDH Failed: " . $e->getMessage() . "\n";
$allPassed = false;
}
// 6. PGP Armor Verification
try {
echo "📦 Testing PGP ASCII Armor... ";
$armored = PGPKeyManager::enarmor($testMessage, 'MESSAGE', ['Version' => 'CompleteOpenPGP Test']);
$unarmored = PGPKeyManager::unarmor($armored, 'MESSAGE');
if ($unarmored === $testMessage) {
echo "✅ PGP Armor Passed\n";
} else {
throw new Exception("PGP Armor unarmor mismatch.");
}
} catch (Exception $e) {
echo "❌ PGP Armor Failed: " . $e->getMessage() . "\n";
$allPassed = false;
}
echo "\n===========================================\n";
if ($allPassed) {
echo "🎉 SUCCESS: CompleteOpenPGP is fully loaded and working!\n";
} else {
echo "⚠️ FAILURE: Some cryptographic algorithms failed.\n";
exit(1);
}
echo "===========================================\n";