Create keys:

var csp = new RSACryptoServiceProvider(keyStrength);
var privateKey = csp.ExportCspBlob(true);
var publicKey = csp.ExportCspBlob(false);

Sign data:
var csp = new RSACryptoServiceProvider();
csp.Clear();
csp.ImportCspBlob(File.ReadAllBytes(privateKeyFile));
var sig = csp.SignData(data, new SHA1CryptoServiceProvider());

Verify data:

csp.Clear();
csp.ImportCspBlob(File.ReadAllBytes(publicKeyFile));
if (csp.VerifyData(data, new SHA1CryptoServiceProvider(), sig)) {
    Console.WriteLine("Data is OK");
} else {
    Console.WriteLine("Data is not OK");
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.