Η ψηφιακή υπογραφή ελέγχει την αυθεντικότητα και την ακεραιότητα μηνύματος. Χρησιμοποιεί ζεύγος κλειδιών (ιδιωτικό/δημόσιο). Ο αποστολέας κρυπτογραφεί με το ιδιωτικό, ο παραλήπτης αποκρυπτογραφεί με το δημόσιο.
private bool VerifyCommand(string text, byte[] signature, string certPath)
{
X509Certificate2 cert = new X509Certificate2(certPath);
RSACryptoServiceProvider csp = (RSACryptoServiceProvider)cert.PublicKey.Key;
SHA1Managed sha1 = new SHA1Managed();
UnicodeEncoding encoding = new UnicodeEncoding();
byte[] data = encoding.GetBytes(text);
byte[] hash = sha1.ComputeHash(data);
return csp.VerifyHash(hash, CryptoConfig.MapNameToOID("SHA1"), signature);
}
if (VerifyCommand("POST TRANSACTION", signature, @"C:\mycert.cer"))
MessageBox.Show("POST command received...");
else if (VerifyCommand("CANCEL TRANSACTION", signature, @"C:\mycert.cer"))
MessageBox.Show("Cancel command received...");
else if (VerifyCommand("RETRIEVE TRANSACTION", signature, @"C:\mycert.cer"))
MessageBox.Show("RETRIEVE Transaction received...");
else
MessageBox.Show("Signature is not valid");
Πνευματικά δικαιώματα © Γνώση Υπολογιστών Όλα τα δικαιώματα διατηρούνται.