EPPlus - Create and validate digital signature

橙三吉。 提交于 2021-01-28 03:32:55

问题


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


回答1:


Maybe you can go with a detached signature.

You can create a signature using the following code:

X509Certificate2 certificate = new X509Certificate2(certPath, password);

byte[] signature;

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

where data is a byte array

Then store it to an external file

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);
}

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

Tell me if it worked =)



来源:https://stackoverflow.com/questions/53648640/epplus-create-and-validate-digital-signature

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!