diff options
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/src/asn1/pkcs/RSAPrivateKeyStructure.cs | 50 | ||||
-rw-r--r-- | crypto/src/crypto/parameters/RsaPrivateCrtKeyParameters.cs | 190 |
2 files changed, 120 insertions, 120 deletions
diff --git a/crypto/src/asn1/pkcs/RSAPrivateKeyStructure.cs b/crypto/src/asn1/pkcs/RSAPrivateKeyStructure.cs index 721299105..738a97eb4 100644 --- a/crypto/src/asn1/pkcs/RSAPrivateKeyStructure.cs +++ b/crypto/src/asn1/pkcs/RSAPrivateKeyStructure.cs @@ -9,14 +9,14 @@ namespace Org.BouncyCastle.Asn1.Pkcs public class RsaPrivateKeyStructure : Asn1Encodable { - private readonly BigInteger modulus; - private readonly BigInteger publicExponent; - private readonly BigInteger privateExponent; - private readonly BigInteger prime1; - private readonly BigInteger prime2; - private readonly BigInteger exponent1; - private readonly BigInteger exponent2; - private readonly BigInteger coefficient; + private readonly BigInteger modulus; + private readonly BigInteger publicExponent; + private readonly BigInteger privateExponent; + private readonly BigInteger prime1; + private readonly BigInteger prime2; + private readonly BigInteger exponent1; + private readonly BigInteger exponent2; + private readonly BigInteger coefficient; public static RsaPrivateKeyStructure GetInstance(Asn1TaggedObject obj, bool isExplicit) { @@ -33,14 +33,14 @@ namespace Org.BouncyCastle.Asn1.Pkcs } public RsaPrivateKeyStructure( - BigInteger modulus, - BigInteger publicExponent, - BigInteger privateExponent, - BigInteger prime1, - BigInteger prime2, - BigInteger exponent1, - BigInteger exponent2, - BigInteger coefficient) + BigInteger modulus, + BigInteger publicExponent, + BigInteger privateExponent, + BigInteger prime1, + BigInteger prime2, + BigInteger exponent1, + BigInteger exponent2, + BigInteger coefficient) { this.modulus = modulus; this.publicExponent = publicExponent; @@ -56,18 +56,18 @@ namespace Org.BouncyCastle.Asn1.Pkcs public RsaPrivateKeyStructure( Asn1Sequence seq) { - BigInteger version = ((DerInteger) seq[0]).Value; + BigInteger version = ((DerInteger)seq[0]).Value; if (version.IntValue != 0) throw new ArgumentException("wrong version for RSA private key"); - modulus = ((DerInteger) seq[1]).Value; - publicExponent = ((DerInteger) seq[2]).Value; - privateExponent = ((DerInteger) seq[3]).Value; - prime1 = ((DerInteger) seq[4]).Value; - prime2 = ((DerInteger) seq[5]).Value; - exponent1 = ((DerInteger) seq[6]).Value; - exponent2 = ((DerInteger) seq[7]).Value; - coefficient = ((DerInteger) seq[8]).Value; + modulus = ((DerInteger)seq[1]).Value; + publicExponent = ((DerInteger)seq[2]).Value; + privateExponent = ((DerInteger)seq[3]).Value; + prime1 = ((DerInteger)seq[4]).Value; + prime2 = ((DerInteger)seq[5]).Value; + exponent1 = ((DerInteger)seq[6]).Value; + exponent2 = ((DerInteger)seq[7]).Value; + coefficient = ((DerInteger)seq[8]).Value; } public BigInteger Modulus diff --git a/crypto/src/crypto/parameters/RsaPrivateCrtKeyParameters.cs b/crypto/src/crypto/parameters/RsaPrivateCrtKeyParameters.cs index e5ed0a8b6..557ee94e2 100644 --- a/crypto/src/crypto/parameters/RsaPrivateCrtKeyParameters.cs +++ b/crypto/src/crypto/parameters/RsaPrivateCrtKeyParameters.cs @@ -7,29 +7,29 @@ using Org.BouncyCastle.Asn1.Pkcs; namespace Org.BouncyCastle.Crypto.Parameters { public class RsaPrivateCrtKeyParameters - : RsaKeyParameters + : 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) + 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; + 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; @@ -37,82 +37,82 @@ namespace Org.BouncyCastle.Crypto.Parameters this.qInv = qInv; } - public RsaPrivateCrtKeyParameters(RsaPrivateKeyStructure rsaPrivateKey) - : this( - rsaPrivateKey.Modulus, - rsaPrivateKey.PublicExponent, - rsaPrivateKey.PrivateExponent, - rsaPrivateKey.Prime1, - rsaPrivateKey.Prime2, - rsaPrivateKey.Exponent1, - rsaPrivateKey.Exponent2, - rsaPrivateKey.Coefficient - ) - { } - - public BigInteger PublicExponent + public RsaPrivateCrtKeyParameters(RsaPrivateKeyStructure rsaPrivateKey) + : this( + rsaPrivateKey.Modulus, + rsaPrivateKey.PublicExponent, + rsaPrivateKey.PrivateExponent, + rsaPrivateKey.Prime1, + rsaPrivateKey.Prime2, + rsaPrivateKey.Exponent1, + rsaPrivateKey.Exponent2, + rsaPrivateKey.Coefficient) + { + } + + 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); - } - } + } + + 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); + } + } } |