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"); }
0 reacties