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