+1 vote

I want to encrypt and sign Excel file using ASP.NET

by

1 Answer

0 votes
 
Best answer

Please read the 2 following articles:

Here's the code that shows how to sign and encrypt email containing attachment:

MailBuilder b = new MailBuilder();
b.From.Add(new MailBox("alice@example.com", "Alice"));
b.To.Add(new MailBox("bob@example.com", "Bob"));
b.Subject = "Test";
b.Html = "This is <strong>signed and encrypted</strong> message.";
b.AddAttachment(@"c:\report.xls");

b.SignWith(new X509Certificate2("AliceCertWithPrivateKey.pfx", ""));
b.EncryptWith(new X509Certificate2("AlicePublicCertificate.pfx", ""));
b.EncryptWith(new X509Certificate2("BobPublicCertificate.pfx", ""));

IMail email = b.Create();

Remember to encrypt your emails with both sender’s and receiver’s certificates.
This way both parties are able to decrypt such emails.

Sending encrypted and signed email is also easy:

using (Smtp client = new Smtp())
{
    client.Connect("smtp.example.com"); // or ConnectSSL
    client.UseBestLogin("user", "password");
    client.SendMessage(email);
    client.Close();
}
by (298k points)
...