Searching for how signing is done I've come across some fairly elaborate code samples. But the following code seems to be enough. Is there something missing here like a salt for example, or are salts unnecessary when just signing? I'm not encrypting, just signing.
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
byte[] data = Encoding.ASCII.GetBytes("hello");
byte[] signature = rsa.SignData(data, "SHA1");
byte[] dataTest = Encoding.ASCII.GetBytes("hello");
bool verified = rsa.VerifyData(dataTest, "SHA1", signature);
if (verified) Text = "True"; else Text = "Untrue";
Are salts unnecessary when just signing?
Salting is necessary if your task is to prevent precomputation of hashes of known messages where the hash is being used as a shared secret. If that's not your application then there is no need to salt.
If you do not understand why you need a salt, see my series of articles on that topic:
http://blogs.msdn.com/b/ericlippert/archive/tags/salt/
Is there something missing here?
Yes, the most important step is missing. How are you going to communicate the public key? The security of the whole system relies upon that step, which you have not even mentioned.
Suppose Alice wishes to send a message to Bob and Bob wishes to verify that it came from Alice. They do the following:
Is this correct?
No. The conclusion is incorrect. The conclusion should be:
The original conclusion is only correct if Bob has additional evidence that he has Alice's public key. Because Bob could be in this situation:
And now the whole thing has gone to hell. Mallory can now publish messages that Bob believes come from Alice, and Alice cannot!
You have to say how you are going to securely publish the public key. The entire system relies on two things: that the private keys stay private, and that there is some mechanism by which public keys can be correctly associated with their owners.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With