This repository was archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
183 lines (177 loc) · 8.67 KB
/
Program.cs
File metadata and controls
183 lines (177 loc) · 8.67 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
using System;
namespace BirdolCrypt
{
class Program
{
static int Main(string[] args)
{
int argc = args.Length;
if (argc < 1)
{
Console.Error.WriteLine("** Error: insufficient arguments");
return 1;
}
string cmd = args[0];
switch(cmd) {
case "keygen":
if (argc < 3)
{
Console.Error.WriteLine("** Error: insufficient arguments");
return 1;
}
{
string name = args[1];
string keyType = args[2];
switch (keyType)
{
case "rsa-1024":
CryptoProvider CryptoRsa1024 = new CryptoProvider(KeyType.RSA1024);
CryptoRsa1024.ExportPrivKeyFile(name);
Console.Write(CryptoRsa1024.PubKey);
break;
case "rsa-2048":
CryptoProvider CryptoRsa2048 = new CryptoProvider(KeyType.RSA2048);
CryptoRsa2048.ExportPrivKeyFile(name);
Console.Write(CryptoRsa2048.PubKey);
break;
case "rsa-4096":
CryptoProvider CryptoRsa4096 = new CryptoProvider(KeyType.RSA4096);
CryptoRsa4096.ExportPrivKeyFile(name);
Console.Write(CryptoRsa4096.PubKey);
break;
case "ecdsa":
CryptoProvider CryptoEcdsa = new CryptoProvider(KeyType.ECDSA);
CryptoEcdsa.ExportPrivKeyFile(name);
Console.Write(CryptoEcdsa.PubKey);
break;
default:
Console.Error.WriteLine("** Error: invalid keytype specified");
Console.Error.WriteLine("Available keytype: rsa-1024, rsa-2048, rsa-4096, ecdsa");
return 1;
}
}
break;
case "makepub":
if (argc < 3)
{
Console.Error.WriteLine("** Error: insufficient arguments");
return 1;
}
{
string keyType = args[1];
string privKeyFile = args[2];
switch (keyType)
{
case "rsa-1024":
CryptoProvider CryptoRsa1024 = new CryptoProvider(KeyType.RSA1024, privKeyFile);
CryptoRsa1024.ExportPubKeyFile(privKeyFile.Replace(".priv", ""));
break;
case "rsa-2048":
CryptoProvider CryptoRsa2048 = new CryptoProvider(KeyType.RSA2048, privKeyFile);
CryptoRsa2048.ExportPubKeyFile(privKeyFile.Replace(".priv", ""));
break;
case "rsa-4096":
CryptoProvider CryptoRsa4096 = new CryptoProvider(KeyType.RSA4096, privKeyFile);
CryptoRsa4096.ExportPubKeyFile(privKeyFile.Replace(".priv", ""));
break;
case "ecdsa":
CryptoProvider CryptoEcdsa = new CryptoProvider(KeyType.ECDSA, privKeyFile);
CryptoEcdsa.ExportPubKeyFile(privKeyFile.Replace(".priv", ""));
break;
default:
Console.Error.WriteLine("** Error: invalid keytype specified");
Console.Error.WriteLine("Available keytype: rsa-1024, rsa-2048, rsa-4096, ecdsa");
return 1;
}
}
break;
case "sign":
if (argc < 4)
{
Console.Error.WriteLine("** Error: insufficient arguments");
return 1;
}
{
string input = args[1];
string keyType = args[2];
string keyfile = args[3];
switch (keyType)
{
case "rsa-1024":
CryptoProvider CryptoRsa1024 = new CryptoProvider(KeyType.RSA1024, keyfile);
Console.Write(Convert.ToHexString(CryptoRsa1024.Sign(input)));
break;
case "rsa-2048":
CryptoProvider CryptoRsa2048 = new CryptoProvider(KeyType.RSA2048, keyfile);
Console.Write(Convert.ToHexString(CryptoRsa2048.Sign(input)));
break;
case "rsa-4096":
CryptoProvider CryptoRsa4096 = new CryptoProvider(KeyType.RSA4096, keyfile);
Console.Write(Convert.ToHexString(CryptoRsa4096.Sign(input)));
break;
case "ecdsa":
CryptoProvider CryptoEcdsa = new CryptoProvider(KeyType.ECDSA, keyfile);
Console.Write(Convert.ToHexString(CryptoEcdsa.Sign(input)));
break;
default:
Console.Error.WriteLine("** Error: invalid keytype specified");
Console.Error.WriteLine("Available keytype: rsa-1024, rsa-2048, rsa-4096, ecdsa");
return 1;
}
}
break;
case "verify":
if (argc < 5)
{
Console.Error.WriteLine("** Error: insufficient arguments");
return 1;
}
{
string msg = args[1];
string signature = args[2];
string keyType = args[3];
string pubKeyFile = args[4];
CryptoProvider Crypto;
switch (keyType)
{
case "rsa-1024":
Crypto = new CryptoProvider(KeyType.RSA1024, pubKeyFile, true);
break;
case "rsa-2048":
Crypto = new CryptoProvider(KeyType.RSA2048, pubKeyFile, true);
break;
case "rsa-4096":
Crypto = new CryptoProvider(KeyType.RSA2048, pubKeyFile, true);
break;
case "ecdsa":
Crypto = new CryptoProvider(KeyType.ECDSA, pubKeyFile, true);
break;
default:
Console.Error.WriteLine("** Error: invalid keytype specified");
Console.Error.WriteLine("Available keytype: rsa-1024, rsa-2048, rsa-4096, ecdsa");
return 1;
}
if (Crypto.Verify(msg, signature))
{
Console.WriteLine("This signature is valid!");
return 0;
}
else
{
Console.WriteLine("This signature is invalid!");
return 0;
}
}
case "uuid":
CryptoProvider uuid = new CryptoProvider(KeyType.None);
Console.WriteLine(uuid.CryptoUuid());
break;
default:
Console.Error.WriteLine("**Error: invalid command");
Console.Error.WriteLine("Available commands: keygen, makepub, sign, verify, uuid");
return 1;
}
return 0;
}
}
}