I have some questions that I would like to inquire about. I would greatly appreciate it if you could receive a timely response
Generate a PFX certificate using the. net built-in X509Certificates and make aspose. word the latest version 23.11.0. Add a digital signature to the Word document and use the certificate generated above to add a digital signature to Excel, which is also the latest version 23.11.0. The signature can be added normally. However, the Windows platform version displayed in the Word document signature is 6.1, while the Windows platform version displayed in the Excel document signature is 5.1
The core code is as follows
public static void generateCer()
{
// 生成 RSA 密钥对
using (var rsa = new RSACryptoServiceProvider(2048))
{
// 创建证书请求
var certificateRequest = new CertificateRequest(
"CN=myCer",
rsa,
HashAlgorithmName.SHA256,
RSASignaturePadding.Pkcs1);
// 创建证书
var certificate = certificateRequest.CreateSelfSigned(DateTimeOffset.Now, DateTimeOffset.Now.AddYears(1));
// 将证书及私钥保存为.pfx文件
byte[] pfxBytes = certificate.Export(X509ContentType.Pfx, "Q123456");
// 保存为文件
System.IO.File.WriteAllBytes("myCer.pfx", pfxBytes);
}
//word
// 文档目录的路径
CertificateHolder certHolder = CertificateHolder.Create(certFilePath, passWd);
SignOptions signOptions = new SignOptions
{
Comments = "Document was signed by Aspose",
SignTime = DateTime.UtcNow,
};
DigitalSignatureUtil.Sign(sourceWordPath, outputWordPath, certHolder, signOptions);
//excel
var sourceDir = AppDomain.CurrentDomain.BaseDirectory;
string certFileName = sourceDir + "123.pfx";
string password = "ABCD123456";
Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(sourceDir + "test.xlsx");
Aspose.Cells.DigitalSignatures.DigitalSignatureCollection dsCollection = new Aspose.Cells.DigitalSignatures.DigitalSignatureCollection();
X509Certificate2 certificate = new X509Certificate2(certFileName, password);
Aspose.Cells.DigitalSignatures.DigitalSignature signature = new Aspose.Cells.DigitalSignatures.DigitalSignature(certificate, "Aspose.Cells added new digital signature in existing digitally signed workbook.", DateTime.UtcNow);
dsCollection.Add(signature);
workbook.AddDigitalSignature(dsCollection);
workbook.Save(sourceDir + "outputDigitallySignedByCells.xlsx");
workbook.Dispose();
resultImg