github #237 - gost 2012 parsing
2 files changed, 20 insertions, 5 deletions
diff --git a/crypto/src/asn1/pkcs/PrivateKeyInfo.cs b/crypto/src/asn1/pkcs/PrivateKeyInfo.cs
index ba9ef6a53..c5c7c3a2f 100644
--- a/crypto/src/asn1/pkcs/PrivateKeyInfo.cs
+++ b/crypto/src/asn1/pkcs/PrivateKeyInfo.cs
@@ -167,6 +167,11 @@ namespace Org.BouncyCastle.Asn1.Pkcs
get { return privateKeyAlgorithm; }
}
+ public virtual Asn1OctetString PrivateKeyData
+ {
+ get { return privateKey; }
+ }
+
public virtual Asn1Object ParsePrivateKey()
{
return Asn1Object.FromByteArray(privateKey.GetOctets());
diff --git a/crypto/src/security/PrivateKeyFactory.cs b/crypto/src/security/PrivateKeyFactory.cs
index b72ece365..4c7a91ecf 100644
--- a/crypto/src/security/PrivateKeyFactory.cs
+++ b/crypto/src/security/PrivateKeyFactory.cs
@@ -206,15 +206,25 @@ namespace Org.BouncyCastle.Security
gostParams.PublicKeyParamSet,
gostParams.DigestParamSet,
gostParams.EncryptionParamSet);
- Asn1Encodable privKey = keyInfo.ParsePrivateKey();
- if (privKey is DerInteger)
+
+ Asn1OctetString privEnc = keyInfo.PrivateKeyData;
+ if (privEnc.GetOctets().Length == 32 || privEnc.GetOctets().Length == 64)
{
- d = DerInteger.GetInstance(privKey).PositiveValue;
+ byte[] dVal = Arrays.Reverse(privEnc.GetOctets());
+ d = new BigInteger(1, dVal);
}
else
{
- byte[] dVal = Arrays.Reverse(Asn1OctetString.GetInstance(privKey).GetOctets());
- d = new BigInteger(1, dVal);
+ Asn1Encodable privKey = keyInfo.ParsePrivateKey();
+ if (privKey is DerInteger)
+ {
+ d = DerInteger.GetInstance(privKey).PositiveValue;
+ }
+ else
+ {
+ byte[] dVal = Arrays.Reverse(Asn1OctetString.GetInstance(privKey).GetOctets());
+ d = new BigInteger(1, dVal);
+ }
}
}
else
|