-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsshv2.html
132 lines (118 loc) · 4.05 KB
/
sshv2.html
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
132
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SSH Key Generator</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f0f0f0;
margin: 0;
}
.container {
text-align: center;
background: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
max-width: 600px;
width: 100%;
}
button {
background-color: #007bff;
color: white;
border: none;
padding: 10px 20px;
cursor: pointer;
font-size: 16px;
border-radius: 5px;
margin-bottom: 20px;
}
button:hover {
background-color: #0056b3;
}
textarea {
width: 100%;
height: 150px;
padding: 10px;
box-sizing: border-box;
border: 1px solid #ccc;
border-radius: 5px;
resize: none;
margin-bottom: 20px;
}
.save-button {
margin-top: 10px;
background-color: #28a745;
}
.save-button:hover {
background-color: #218838;
}
h2 {
margin-bottom: 10px;
}
</style>
</head>
<body>
<div class="container">
<h1>SSH Key Generator</h1>
<button id="generate">Generate SSH Keys</button>
<div>
<h2>Public Key</h2>
<textarea id="public-key" readonly></textarea>
<button id="save-public-key" class="save-button">Save Public Key</button>
</div>
<div>
<h2>Private Key</h2>
<textarea id="private-key" readonly></textarea>
<button id="save-private-key" class="save-button">Save Private Key</button>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/forge/0.10.0/forge.min.js"></script>
<script>
document.getElementById('generate').addEventListener('click', generateSSHKeys);
document.getElementById('save-public-key').addEventListener('click', savePublicKey);
document.getElementById('save-private-key').addEventListener('click', savePrivateKey);
function generateSSHKeys() {
// Generate RSA key pair
forge.pki.rsa.generateKeyPair({ bits: 2048, workers: 2 }, function(err, keypair) {
if (err) {
console.error(err);
return;
}
// Convert the private key to PEM format
var privateKeyPem = forge.pki.privateKeyToPem(keypair.privateKey);
// Convert the public key to OpenSSH format
var sshPublicKey = forge.ssh.publicKeyToOpenSSH(keypair.publicKey);
// Display the keys in the text areas
document.getElementById('private-key').value = privateKeyPem;
document.getElementById('public-key').value = sshPublicKey;
});
}
function savePublicKey() {
var publicKey = document.getElementById('public-key').value;
downloadFile(publicKey, 'public_key.pub');
}
function savePrivateKey() {
var privateKey = document.getElementById('private-key').value;
downloadFile(privateKey, 'private_key.pem');
}
function downloadFile(content, fileName) {
var blob = new Blob([content], { type: 'text/plain' });
var url = URL.createObjectURL(blob);
var a = document.createElement('a');
a.href = url;
a.download = fileName;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
</script>
</body>
</html>