secret
Created

ECDSA in C#

  • Download Gist
ECDSA.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
void Main()
{
byte[] publickey;
byte[] data;
byte[] signature;
 
using (var dsa = new ECDsaCng(256))
{
dsa.HashAlgorithm = CngAlgorithm.Sha256;
publickey = dsa.Key.Export(CngKeyBlobFormat.EccPublicBlob);
 
data = new byte[] { 21, 5, 8, 12, 207 };
 
signature = dsa.SignData(data);
}
signature.Length.Dump();
Convert.ToBase64String(signature).Dump();
 
using (ECDsaCng ecsdKey = new ECDsaCng(CngKey.Import(publickey, CngKeyBlobFormat.EccPublicBlob)))
{
if (ecsdKey.VerifyData(data, signature))
Console.WriteLine("Data is good");
else
Console.WriteLine("Data is bad");
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.