EPPlus-创建和验证数字签名 [英] EPPlus - Create and validate digital signature

查看:92
本文介绍了EPPlus-创建和验证数字签名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用EPPlus将数字签名添加到excel文档并验证现有excel文档的数字签名?

is it possible to add a digital signature to an excel document with EPPlus and validate a digital signature of an existing excel document?

推荐答案

也许您可以使用独立签名.

Maybe you can go with a detached signature.

您可以使用以下代码创建签名:

X509Certificate2 certificate = new X509Certificate2(certPath, password);

byte[] signature;

using (RSA rsa = certificate.GetRSAPrivateKey())
{
    signature = rsa.SignData(data, HashAlgorithmName.SHA512, RSASignaturePadding.Pkcs1);
}

其中数据是字节数组

然后将其存储到外部文件

Then store it to an external file

验证签名,您需要xlsx文件和外部签名文件.

For validating the signature you need your xlsx file and the external signature file.

然后您可以使用以下代码验证签名

Then you can verify the signature using the following code

X509Certificate2 publicCertificate = new X509Certificate2(certPath);

var valid = false;
using (RSA rsa = publicCertificate.GetRSAPublicKey())
{
    valid = rsa.VerifyData(fileData, signatureData, HashAlgorithmName.SHA512, RSASignaturePadding.Pkcs1);
}

其中fileData是xlsx文件的字节数组,signatureData是签名文件的字节数组

where fileData is a byte array of your xlsx file and signatureData is a byte array of your signature file

告诉我它是否有效=)

这篇关于EPPlus-创建和验证数字签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆