-
Notifications
You must be signed in to change notification settings - Fork 0
/
RSAKeyGeneratorCommand.cs
55 lines (50 loc) · 1.48 KB
/
RSAKeyGeneratorCommand.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
namespace RSA
{
class RSAKeyGeneratorCommand : Command
{
private RSAKeyGenerator keyGenerator;
private void init()
{
this.keyGenerator = new RSAKeyGenerator();
}
private BigInteger inputK()
{
try
{
Console.WriteLine("Enter random decimal integer value: ");
String _k = Console.ReadLine();
BigInteger k = BigInteger.Parse(_k);
return k;
}
catch (Exception)
{
Console.WriteLine("Input is not decimal integer.");
return inputK();
}
}
private void printPublicKey(PublicKey publicKey)
{
Console.WriteLine("Public key: ");
Console.WriteLine("\tn: " + publicKey.N);
Console.WriteLine("\te: " + publicKey.E + "\n");
}
private void printPrivateKey(PrivateKey privateKey)
{
Console.WriteLine("Private key: ");
Console.WriteLine("\tn: " + privateKey.N);
Console.WriteLine("\td: " + privateKey.D + "\n");
}
protected override void doExecute()
{
this.init();
printPublicKey(this.keyGenerator.publicKey);
printPrivateKey(this.keyGenerator.privateKey);
}
}
}