|
7 | 7 | namespace Org.BouncyCastle.Crypto.Parameters
|
8 | 8 | {
|
9 | 9 | public class RsaPrivateCrtKeyParameters
|
10 |
| - : RsaKeyParameters |
| 10 | + : RsaKeyParameters |
11 | 11 | {
|
12 | 12 | private readonly BigInteger e, p, q, dP, dQ, qInv;
|
13 | 13 |
|
14 |
| - public RsaPrivateCrtKeyParameters( |
15 |
| - BigInteger modulus, |
16 |
| - BigInteger publicExponent, |
17 |
| - BigInteger privateExponent, |
18 |
| - BigInteger p, |
19 |
| - BigInteger q, |
20 |
| - BigInteger dP, |
21 |
| - BigInteger dQ, |
22 |
| - BigInteger qInv) |
23 |
| - : base(true, modulus, privateExponent) |
| 14 | + public RsaPrivateCrtKeyParameters( |
| 15 | + BigInteger modulus, |
| 16 | + BigInteger publicExponent, |
| 17 | + BigInteger privateExponent, |
| 18 | + BigInteger p, |
| 19 | + BigInteger q, |
| 20 | + BigInteger dP, |
| 21 | + BigInteger dQ, |
| 22 | + BigInteger qInv) |
| 23 | + : base(true, modulus, privateExponent) |
24 | 24 | {
|
25 |
| - ValidateValue(publicExponent, "publicExponent", "exponent"); |
26 |
| - ValidateValue(p, "p", "P value"); |
27 |
| - ValidateValue(q, "q", "Q value"); |
28 |
| - ValidateValue(dP, "dP", "DP value"); |
29 |
| - ValidateValue(dQ, "dQ", "DQ value"); |
30 |
| - ValidateValue(qInv, "qInv", "InverseQ value"); |
31 |
| - |
32 |
| - this.e = publicExponent; |
| 25 | + ValidateValue(publicExponent, "publicExponent", "exponent"); |
| 26 | + ValidateValue(p, "p", "P value"); |
| 27 | + ValidateValue(q, "q", "Q value"); |
| 28 | + ValidateValue(dP, "dP", "DP value"); |
| 29 | + ValidateValue(dQ, "dQ", "DQ value"); |
| 30 | + ValidateValue(qInv, "qInv", "InverseQ value"); |
| 31 | + |
| 32 | + this.e = publicExponent; |
33 | 33 | this.p = p;
|
34 | 34 | this.q = q;
|
35 | 35 | this.dP = dP;
|
36 | 36 | this.dQ = dQ;
|
37 | 37 | this.qInv = qInv;
|
38 | 38 | }
|
39 | 39 |
|
40 |
| - public RsaPrivateCrtKeyParameters(RsaPrivateKeyStructure rsaPrivateKey) |
41 |
| - : this( |
42 |
| - rsaPrivateKey.Modulus, |
43 |
| - rsaPrivateKey.PublicExponent, |
44 |
| - rsaPrivateKey.PrivateExponent, |
45 |
| - rsaPrivateKey.Prime1, |
46 |
| - rsaPrivateKey.Prime2, |
47 |
| - rsaPrivateKey.Exponent1, |
48 |
| - rsaPrivateKey.Exponent2, |
49 |
| - rsaPrivateKey.Coefficient |
50 |
| - ) |
51 |
| - { } |
52 |
| - |
53 |
| - public BigInteger PublicExponent |
| 40 | + public RsaPrivateCrtKeyParameters(RsaPrivateKeyStructure rsaPrivateKey) |
| 41 | + : this( |
| 42 | + rsaPrivateKey.Modulus, |
| 43 | + rsaPrivateKey.PublicExponent, |
| 44 | + rsaPrivateKey.PrivateExponent, |
| 45 | + rsaPrivateKey.Prime1, |
| 46 | + rsaPrivateKey.Prime2, |
| 47 | + rsaPrivateKey.Exponent1, |
| 48 | + rsaPrivateKey.Exponent2, |
| 49 | + rsaPrivateKey.Coefficient) |
| 50 | + { |
| 51 | + } |
| 52 | + |
| 53 | + public BigInteger PublicExponent |
54 | 54 | {
|
55 | 55 | get { return e; }
|
56 |
| - } |
57 |
| - |
58 |
| - public BigInteger P |
59 |
| - { |
60 |
| - get { return p; } |
61 |
| - } |
62 |
| - |
63 |
| - public BigInteger Q |
64 |
| - { |
65 |
| - get { return q; } |
66 |
| - } |
67 |
| - |
68 |
| - public BigInteger DP |
69 |
| - { |
70 |
| - get { return dP; } |
71 |
| - } |
72 |
| - |
73 |
| - public BigInteger DQ |
74 |
| - { |
75 |
| - get { return dQ; } |
76 |
| - } |
77 |
| - |
78 |
| - public BigInteger QInv |
79 |
| - { |
80 |
| - get { return qInv; } |
81 |
| - } |
82 |
| - |
83 |
| - public override bool Equals( |
84 |
| - object obj) |
85 |
| - { |
86 |
| - if (obj == this) |
87 |
| - return true; |
88 |
| - |
89 |
| - RsaPrivateCrtKeyParameters kp = obj as RsaPrivateCrtKeyParameters; |
90 |
| - |
91 |
| - if (kp == null) |
92 |
| - return false; |
93 |
| - |
94 |
| - return kp.DP.Equals(dP) |
95 |
| - && kp.DQ.Equals(dQ) |
96 |
| - && kp.Exponent.Equals(this.Exponent) |
97 |
| - && kp.Modulus.Equals(this.Modulus) |
98 |
| - && kp.P.Equals(p) |
99 |
| - && kp.Q.Equals(q) |
100 |
| - && kp.PublicExponent.Equals(e) |
101 |
| - && kp.QInv.Equals(qInv); |
102 |
| - } |
103 |
| - |
104 |
| - public override int GetHashCode() |
105 |
| - { |
106 |
| - return DP.GetHashCode() ^ DQ.GetHashCode() ^ Exponent.GetHashCode() ^ Modulus.GetHashCode() |
107 |
| - ^ P.GetHashCode() ^ Q.GetHashCode() ^ PublicExponent.GetHashCode() ^ QInv.GetHashCode(); |
108 |
| - } |
109 |
| - |
110 |
| - private static void ValidateValue(BigInteger x, string name, string desc) |
111 |
| - { |
112 |
| - if (x == null) |
113 |
| - throw new ArgumentNullException(name); |
114 |
| - if (x.SignValue <= 0) |
115 |
| - throw new ArgumentException("Not a valid RSA " + desc, name); |
116 |
| - } |
117 |
| - } |
| 56 | + } |
| 57 | + |
| 58 | + public BigInteger P |
| 59 | + { |
| 60 | + get { return p; } |
| 61 | + } |
| 62 | + |
| 63 | + public BigInteger Q |
| 64 | + { |
| 65 | + get { return q; } |
| 66 | + } |
| 67 | + |
| 68 | + public BigInteger DP |
| 69 | + { |
| 70 | + get { return dP; } |
| 71 | + } |
| 72 | + |
| 73 | + public BigInteger DQ |
| 74 | + { |
| 75 | + get { return dQ; } |
| 76 | + } |
| 77 | + |
| 78 | + public BigInteger QInv |
| 79 | + { |
| 80 | + get { return qInv; } |
| 81 | + } |
| 82 | + |
| 83 | + public override bool Equals( |
| 84 | + object obj) |
| 85 | + { |
| 86 | + if (obj == this) |
| 87 | + return true; |
| 88 | + |
| 89 | + RsaPrivateCrtKeyParameters kp = obj as RsaPrivateCrtKeyParameters; |
| 90 | + |
| 91 | + if (kp == null) |
| 92 | + return false; |
| 93 | + |
| 94 | + return kp.DP.Equals(dP) |
| 95 | + && kp.DQ.Equals(dQ) |
| 96 | + && kp.Exponent.Equals(this.Exponent) |
| 97 | + && kp.Modulus.Equals(this.Modulus) |
| 98 | + && kp.P.Equals(p) |
| 99 | + && kp.Q.Equals(q) |
| 100 | + && kp.PublicExponent.Equals(e) |
| 101 | + && kp.QInv.Equals(qInv); |
| 102 | + } |
| 103 | + |
| 104 | + public override int GetHashCode() |
| 105 | + { |
| 106 | + return DP.GetHashCode() ^ DQ.GetHashCode() ^ Exponent.GetHashCode() ^ Modulus.GetHashCode() |
| 107 | + ^ P.GetHashCode() ^ Q.GetHashCode() ^ PublicExponent.GetHashCode() ^ QInv.GetHashCode(); |
| 108 | + } |
| 109 | + |
| 110 | + private static void ValidateValue(BigInteger x, string name, string desc) |
| 111 | + { |
| 112 | + if (x == null) |
| 113 | + throw new ArgumentNullException(name); |
| 114 | + if (x.SignValue <= 0) |
| 115 | + throw new ArgumentException("Not a valid RSA " + desc, name); |
| 116 | + } |
| 117 | + } |
118 | 118 | }
|
0 commit comments