请告诉我最好的方式进行数字签名使用.NET下载一个zip文件数字签名、告诉我、最好的、方式

2023-09-04 04:55:23 作者:女人的眼泪是珍珠

请告诉我通过一个asp.net根据网站

Whats the best way to digitally sign a file server side with .Net before offering it for download via an asp.net based web site

在另外我如何触发检查签名的,因此证明在下载过程中在网络浏览器尚未tmapered与文件

In addition how do I trigger checking of the signature and hence prove the file has not been tmapered with during the download process in a web browser

推荐答案

一个签名不需要被包含在ZIP文件,也可以是一个独立的签名。所以,你可以有拉链,让别人来验证签名,这通常只是由一系列十六进制或Base64字符,带外与你编写一个应用程序。

A signature does not need to be included with the ZIP file, it can be a "detached" signature. So you could have the zip and allow someone to verify the sig, which is usually just a series of hex or base64 characters, out of band with an app you write.

目前的高级别,签名的步骤是:

At a high-level, the signing steps are:

AsymmetricAlgorithm privateKey = certificate.PrivateKey;
byte[] buffer = Encoding.Default.GetBytes(<data from the zip>);
byte[] signature = privateKey.SignData(buffer, new SHA1Managed());

和验证:

RSACryptoServiceProvider publicKey =  certificate.PublicKey.Key as RSACryptoServiceProvider;
bool verify = publicKey.VerifyData(buffer, new SHA1Managed(), signature);