This is not a 100% c# or ASP.NET question, it's rather a mixture of security and programming. So I apologize ahead. I need to integrate file signing module to my ASP.NET web application. I also need to write a utility application that will verify the signature. I know how to both sign a file and verify it. Here's how I do signing:
private byte[] SignFile(byte[] fileData){
X509Certificate2 cert=GetCertificate();
RSACryptoServiceProvider csp = cert.PrivateKey;
SHA1Managed sha1 = new SHA1Managed();
byte[] hash = sha1.ComputeHash(fileData);
return csp.SignData(hash, CryptoConfig.MapNameToOID("SHA1"));
}
So far so good. On the other hand, when verifying I will need the public key. So here's my question. Do I need to send the certificate with the signed file so that the other side can take the public key to verify the signature. If so, this brings another question to mind: Can't someone else take the private key from attached certificate to edit the file and sign it again? What is the proper way of doing this?