question

SamAmin-9403 avatar image
0 Votes"
SamAmin-9403 asked XingyuZhao-MSFT edited

How do I DER encode a signature in .NET Core 3.1?

Hi,

I have a requirement for a new integration we are building to sign the contents of the request we send using a private key, then DER Encode it , and Base 64 Encode it.

I can do it in .Net Core 5.0 easily as follows:

 byte[] signedData;
     var dsa = ECDsa.Create();
     dsa.ImportECPrivateKey(Convert.FromBase64String(key), out _);
     signedData = dsa.SignData(requestByteArray, 
          HashAlgorithmName.SHA256,DSASignatureFormat.Rfc3279DerSequence);
     string base64Signature = Convert.ToBase64String(signedData);

But, unfortunately, our project is .Net Core 3.1 and we're not planning on upgrading it at the moment.

In 3.1 this is the only available option for the SignData method, and I need to find a way to DER encode the output but I can't find any way to do it. I'm sure it's doable using BouncyCastle, but I can't figure it out from the documentation.

 signedData = dsa.SignData(requestByteArray, HashAlgorithmName.SHA256);

Any help here would be highly appreciated.

Thanks
Sam



dotnet-csharpdotnet-aspnet-core-security
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @SamAmin-9403 ,

I need to find a way to DER encode the output

It seems that .NET Core 3.1 does not provide enough support for it. Upgrading the NET version should be a better choice.




1 Vote 1 ·

0 Answers