Skip to content

Commit

Permalink
KSM-476 fixed parsing keys in DER format
Browse files Browse the repository at this point in the history
  • Loading branch information
idimov-keeper committed Nov 21, 2023
1 parent 9b19035 commit 944b633
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions sdk/dotNet/SecretsManager/CryptoUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using Org.BouncyCastle.Asn1.Pkcs;
using Org.BouncyCastle.Asn1.Sec;

namespace SecretsManager
{
Expand Down Expand Up @@ -105,8 +107,11 @@ private static ECPublicKeyParameters ImportPublicKey(byte[] key)
}

private static ECPrivateKeyParameters ImportPrivateKey(byte[] privateKeyDer)
{
return new ECPrivateKeyParameters(new BigInteger(1, privateKeyDer.Skip(36).Take(32).ToArray()), ECParameters);
{
var privateKeyInfo = PrivateKeyInfo.GetInstance(privateKeyDer);
var privateKeyStructure = ECPrivateKeyStructure.GetInstance(privateKeyInfo.ParsePrivateKey());
var privateKeyValue = privateKeyStructure.GetKey();
return new ECPrivateKeyParameters(privateKeyValue, ECParameters);
}

private static byte[] GetECIESSymmetricKey(ICipherParameters privateKey, ICipherParameters recipientPublicKey)
Expand Down

0 comments on commit 944b633

Please sign in to comment.