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
|
using System;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Math;
namespace Org.BouncyCastle.Crypto.Parameters
{
public class RsaPrivateCrtKeyParameters
: RsaKeyParameters
{
private readonly BigInteger e, p, q, dP, dQ, qInv;
public RsaPrivateCrtKeyParameters(
BigInteger modulus,
BigInteger publicExponent,
BigInteger privateExponent,
BigInteger p,
BigInteger q,
BigInteger dP,
BigInteger dQ,
BigInteger qInv)
: base(true, modulus, privateExponent)
{
ValidateValue(publicExponent, "publicExponent", "exponent");
ValidateValue(p, "p", "P value");
ValidateValue(q, "q", "Q value");
ValidateValue(dP, "dP", "DP value");
ValidateValue(dQ, "dQ", "DQ value");
ValidateValue(qInv, "qInv", "InverseQ value");
this.e = publicExponent;
this.p = p;
this.q = q;
this.dP = dP;
this.dQ = dQ;
this.qInv = qInv;
}
public BigInteger PublicExponent
{
get { return e; }
}
public BigInteger P
{
get { return p; }
}
public BigInteger Q
{
get { return q; }
}
public BigInteger DP
{
get { return dP; }
}
public BigInteger DQ
{
get { return dQ; }
}
public BigInteger QInv
{
get { return qInv; }
}
public override bool Equals(
object obj)
{
if (obj == this)
return true;
RsaPrivateCrtKeyParameters kp = obj as RsaPrivateCrtKeyParameters;
if (kp == null)
return false;
return kp.DP.Equals(dP)
&& kp.DQ.Equals(dQ)
&& kp.Exponent.Equals(this.Exponent)
&& kp.Modulus.Equals(this.Modulus)
&& kp.P.Equals(p)
&& kp.Q.Equals(q)
&& kp.PublicExponent.Equals(e)
&& kp.QInv.Equals(qInv);
}
public override int GetHashCode()
{
return DP.GetHashCode() ^ DQ.GetHashCode() ^ Exponent.GetHashCode() ^ Modulus.GetHashCode()
^ P.GetHashCode() ^ Q.GetHashCode() ^ PublicExponent.GetHashCode() ^ QInv.GetHashCode();
}
private static void ValidateValue(BigInteger x, string name, string desc)
{
if (x == null)
throw new ArgumentNullException(name);
if (x.SignValue <= 0)
throw new ArgumentException("Not a valid RSA " + desc, name);
}
}
}
|