blob: bb6108f2dccd9ff3fc808a5516640860fe8d2b9f (
plain) (
blame)
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
|
using System;
using System.Collections;
using System.IO;
using Org.BouncyCastle.Asn1.Utilities;
using Org.BouncyCastle.Bcpg.OpenPgp;
using Org.BouncyCastle.Utilities.Encoders;
namespace Org.BouncyCastle.Bcpg.OpenPgp.Examples
{
/**
* Basic class which just lists the contents of the public key file passed
* as an argument. If the file contains more than one "key ring" they are
* listed in the order found.
*/
public sealed class PublicKeyRingDump
{
private PublicKeyRingDump()
{
}
public static string GetAlgorithm(
PublicKeyAlgorithmTag algId)
{
switch (algId)
{
case PublicKeyAlgorithmTag.RsaGeneral:
return "RsaGeneral";
case PublicKeyAlgorithmTag.RsaEncrypt:
return "RsaEncrypt";
case PublicKeyAlgorithmTag.RsaSign:
return "RsaSign";
case PublicKeyAlgorithmTag.ElGamalEncrypt:
return "ElGamalEncrypt";
case PublicKeyAlgorithmTag.Dsa:
return "DSA";
case PublicKeyAlgorithmTag.EC:
return "EC";
case PublicKeyAlgorithmTag.ECDsa:
return "ECDSA";
case PublicKeyAlgorithmTag.ElGamalGeneral:
return "ElGamalGeneral";
case PublicKeyAlgorithmTag.DiffieHellman:
return "DiffieHellman";
}
return "unknown";
}
public static void Main(
string[] args)
{
Stream fs = File.OpenRead(args[0]);
//
// Read the public key rings
//
PgpPublicKeyRingBundle pubRings = new PgpPublicKeyRingBundle(
PgpUtilities.GetDecoderStream(fs));
fs.Close();
foreach (PgpPublicKeyRing pgpPub in pubRings.GetKeyRings())
{
try
{
//PgpPublicKey pubKey =
pgpPub.GetPublicKey();
}
catch (Exception e)
{
Console.Error.WriteLine(e.Message);
Console.Error.WriteLine(e.StackTrace);
continue;
}
bool first = true;
foreach (PgpPublicKey pgpKey in pgpPub.GetPublicKeys())
{
if (first)
{
Console.WriteLine("Key ID: " + pgpKey.KeyId.ToString("X"));
first = false;
}
else
{
Console.WriteLine("Key ID: " + pgpKey.KeyId.ToString("X") + " (subkey)");
}
Console.WriteLine(" Algorithm: " + GetAlgorithm(pgpKey.Algorithm));
Console.WriteLine(" Fingerprint: " + Hex.ToHexString(pgpKey.GetFingerprint()));
}
}
}
}
}
|