تعيين والتحقق من التواقيع الرقمية
مقدمة
استخدم مربع الحوار للتوقيع الرقمي لربط توقيع رقمي. يُدرِج مربع الحوار للتوقيع الرقمي الشهادات الصالحة. يمكنك استخدام مربع الحوار للتوقيع الرقمي لعرض الشهادات واختيار تلك التي تريد استخدامها. إذا كان لدى دفتر العمل توقيع رقمي، فإن اسم التوقيع يظهر في حقل اسم الشهادة. إذا قمت بالنقر على زر إزالة في مربع الحوار للتوقيع الرقمي، فإن Microsoft Excel يزيل التوقيع الرقمي أيضًا.
كيفية إضافة توقيع رقمي لملف Excel
يوفر Aspose.Cells الفضاء الاسمي Aspose.Cells.DigitalSignatures لأداء المهمة (تعيين والتحقق من التواقيع الرقمية). يحتوي الفضاء الاسمي على بعض الميزات المفيدة لإضافة والتحقق من التواقيع الرقمية.
يرجى رؤية الكود المثالي التالي الذي يصف كيف يمكنك أداء المهمة باستخدام واجهة برمجة التطبيقات Aspose.Cells for .NET.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// dsc is signature collection contains one or more signature needed to sign | |
DigitalSignatureCollection dsc = new DigitalSignatureCollection(); | |
// Cert must contain private key, it can be contructed from cert file or windows certificate collection. aa is password of cert | |
X509Certificate2 cert = new X509Certificate2(dataDir + "mykey2.pfx", "aa"); | |
DigitalSignature ds = new DigitalSignature(cert, "test for sign", DateTime.Now); | |
dsc.Add(ds); | |
Workbook wb = new Workbook(); | |
// wb.SetDigitalSignature signs all signatures in dsc | |
wb.SetDigitalSignature(dsc); | |
wb.Save(dataDir + @"newfile_out.xlsx"); | |
// open the file | |
wb = new Workbook(dataDir + @"newfile_out.xlsx"); | |
System.Console.WriteLine(wb.IsDigitallySigned); | |
// Get digitalSignature collection from workbook | |
dsc = wb.GetDigitalSignature(); | |
foreach (DigitalSignature dst in dsc) | |
{ | |
System.Console.WriteLine(dst.Comments); //test for sign -OK | |
System.Console.WriteLine(dst.SignTime); //11/25/2010 1:22:01 PM -OK | |
System.Console.WriteLine(dst.IsValid); //True -OK | |
} |