summary refs log tree commit diff
path: root/crypto/src/security
diff options
context:
space:
mode:
authorDavid Hook <dgh@cryptoworkshop.com>2020-04-25 13:11:33 +1000
committerDavid Hook <dgh@cryptoworkshop.com>2020-04-25 13:11:33 +1000
commitfac7ac9bfe82e7c4eedf5a7b26bed58e49fa988b (patch)
tree229da03984ecbf55afbd25707ccee29e2523557b /crypto/src/security
parentfixed typo (diff)
downloadBouncyCastle.NET-ed25519-fac7ac9bfe82e7c4eedf5a7b26bed58e49fa988b.tar.xz
github #237 - gost 2012 parsing
Diffstat (limited to 'crypto/src/security')
-rw-r--r--crypto/src/security/PrivateKeyFactory.cs20
1 files changed, 15 insertions, 5 deletions
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