diff options
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/src/asn1/cryptopro/GOST3410PublicKeyAlgParameters.cs | 11 | ||||
-rw-r--r-- | crypto/src/security/PrivateKeyFactory.cs | 23 |
2 files changed, 17 insertions, 17 deletions
diff --git a/crypto/src/asn1/cryptopro/GOST3410PublicKeyAlgParameters.cs b/crypto/src/asn1/cryptopro/GOST3410PublicKeyAlgParameters.cs index 10c45ba4d..ea42a1ec4 100644 --- a/crypto/src/asn1/cryptopro/GOST3410PublicKeyAlgParameters.cs +++ b/crypto/src/asn1/cryptopro/GOST3410PublicKeyAlgParameters.cs @@ -22,16 +22,9 @@ namespace Org.BouncyCastle.Asn1.CryptoPro object obj) { if (obj == null || obj is Gost3410PublicKeyAlgParameters) - { - return (Gost3410PublicKeyAlgParameters) obj; - } - - if (obj is Asn1Sequence) - { - return new Gost3410PublicKeyAlgParameters((Asn1Sequence) obj); - } + return (Gost3410PublicKeyAlgParameters)obj; - throw new ArgumentException("Invalid GOST3410Parameter: " + Platform.GetTypeName(obj)); + return new Gost3410PublicKeyAlgParameters(Asn1Sequence.GetInstance((obj))); } public Gost3410PublicKeyAlgParameters( diff --git a/crypto/src/security/PrivateKeyFactory.cs b/crypto/src/security/PrivateKeyFactory.cs index 8c2ecfdb0..c9e19cc7d 100644 --- a/crypto/src/security/PrivateKeyFactory.cs +++ b/crypto/src/security/PrivateKeyFactory.cs @@ -143,8 +143,7 @@ namespace Org.BouncyCastle.Security if (privKey is DerInteger) { - // TODO Do we need to pass any parameters here? - ec = new ECPrivateKeyStructure(ecP.N.BitLength, ((DerInteger)privKey).Value); + ec = new ECPrivateKeyStructure(ecP.N.BitLength, ((DerInteger)privKey).PositiveValue); } else { @@ -155,14 +154,22 @@ namespace Org.BouncyCastle.Security } else if (algOid.Equals(CryptoProObjectIdentifiers.GostR3410x94)) { - Gost3410PublicKeyAlgParameters gostParams = new Gost3410PublicKeyAlgParameters( - Asn1Sequence.GetInstance(algID.Parameters.ToAsn1Object())); + Gost3410PublicKeyAlgParameters gostParams = Gost3410PublicKeyAlgParameters.GetInstance(algID.Parameters); - DerOctetString derX = (DerOctetString)keyInfo.ParsePrivateKey(); - BigInteger x = new BigInteger(1, Arrays.Reverse(derX.GetOctets())); + Asn1Object privKey = keyInfo.ParsePrivateKey(); + BigInteger x; - return new Gost3410PrivateKeyParameters(x, gostParams.PublicKeyParamSet); - } + if (privKey is DerInteger) + { + x = DerInteger.GetInstance(privKey).PositiveValue; + } + else + { + x = new BigInteger(1, Arrays.Reverse(Asn1OctetString.GetInstance(privKey).GetOctets())); + } + + return new Gost3410PrivateKeyParameters(x, gostParams.PublicKeyParamSet); + } else { throw new SecurityUtilityException("algorithm identifier in key not recognised"); |