问题
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