summary refs log tree commit diff
path: root/crypto/src/openpgp/PgpKeyPair.cs
blob: 6efb03a42d9e38f2ad90b7f00a8f2affa6f238da (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
using System;

using Org.BouncyCastle.Crypto;

namespace Org.BouncyCastle.Bcpg.OpenPgp
{
	/// <remarks>
	/// General class to handle JCA key pairs and convert them into OpenPGP ones.
	/// <p>
	/// A word for the unwary, the KeyId for an OpenPGP public key is calculated from
	/// a hash that includes the time of creation, if you pass a different date to the
	/// constructor below with the same public private key pair the KeyIs will not be the
	/// same as for previous generations of the key, so ideally you only want to do
	/// this once.
	/// </p>
	/// </remarks>
    public class PgpKeyPair
    {
        private readonly PgpPublicKey	pub;
        private readonly PgpPrivateKey	priv;

		public PgpKeyPair(
            PublicKeyAlgorithmTag	algorithm,
            AsymmetricCipherKeyPair	keyPair,
            DateTime				time)
			: this(algorithm, keyPair.Public, keyPair.Private, time)
        {
        }

		public PgpKeyPair(
            PublicKeyAlgorithmTag	algorithm,
            AsymmetricKeyParameter	pubKey,
            AsymmetricKeyParameter	privKey,
            DateTime				time)
        {
            this.pub = new PgpPublicKey(algorithm, pubKey, time);
			this.priv = new PgpPrivateKey(privKey, pub.KeyId);
        }

		/// <summary>Create a key pair from a PgpPrivateKey and a PgpPublicKey.</summary>
		/// <param name="pub">The public key.</param>
		/// <param name="priv">The private key.</param>
        public PgpKeyPair(
            PgpPublicKey	pub,
            PgpPrivateKey	priv)
        {
            this.pub = pub;
            this.priv = priv;
        }

		/// <summary>The keyId associated with this key pair.</summary>
        public long KeyId
        {
            get { return pub.KeyId; }
        }

		public PgpPublicKey PublicKey
        {
			get { return pub; }
        }

		public PgpPrivateKey PrivateKey
        {
			get { return priv; }
        }
    }
}