原創|其它|編輯:郝浩|2012-07-01 21:37:10.000|閱讀 516 次
概述:Aspose.Cells提供Aspose.Cells.DigitalSignatures命名空間,以指定和驗證數字簽名。命名空間包含了一些有用得API簽名/驗證數字簽名。參閱下面代碼示例,了解如何使用Aspose.Cells和.NET APIs分配和驗證數字簽名。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Aspose.Cells提供Aspose.Cells.DigitalSignatures命名空間,以指定和驗證數字簽名。命名空間包含了一些有用得API簽名/驗證數字簽名。參閱下面代碼示例,了解如何使用Aspose.Cells和.NET APIs分配和驗證數字簽名。
[C#]
using System;
using System.IO;
using Aspose.Cells;
using System.Collections;
using System.Text;
using System.Threading;
using Aspose.Cells.Rendering;
using System.Security.Cryptography;
using System.Drawing;
using System.Diagnostics;
using Aspose.Cells.DigitalSignatures;
using System.Security.Cryptography.X509Certificates;
namespace Aspose.Cells.test
{
/// <summary>
/// Summary description for MyTest.
/// </summary>
class MyTest
{
public MyTest()
{
}
[STAThread]
static void Main(string[] args)
{
MyTest test = new MyTest();
test.testSign();
test.testvalidateSign();
Console.ReadLine();
}
internal void testvalidateSign()
{
//instantiate and open the file
Workbook wb = new Workbook(@"e:\test\digital signatures\newfile.xlsx");
//wb.IsDigitallySigned is true when the workbook is signed already.
System.Console.WriteLine(wb.IsDigitallySigned); //True -OK
//get digitalSignature collection from workbook
DigitalSignatureCollection dsc = wb.GetDigitalSignature();
foreach (DigitalSignature ds in dsc)
{
System.Console.WriteLine(ds.Comments); //test for sign -OK
System.Console.WriteLine(ds.SignTime); //11/25/2010 1:22:01 PM -OK
System.Console.WriteLine(ds.IsValid); //True -OK
}
}
internal void testSign()
{
//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.
//123456 is password of cert
X509Certificate2 cert = new X509Certificate2("e:\\test\\digital signatures\\mykey2.pfx", "123456");
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(@"e:\test\digital signatures\newfile.xlsx");
}
}
}
[VB]
Imports System
Imports System.IO
Imports Aspose.Cells
Imports System.Collections
Imports System.Text
Imports System.Threading
Imports Aspose.Cells.Rendering
Imports System.Security.Cryptography
Imports System.Drawing
Imports System.Diagnostics
Imports Aspose.Cells.DigitalSignatures
Imports System.Security.Cryptography.X509Certificates
Namespace Aspose.Cells.test
''' <summary>
''' Summary description for MyTest.
''' </summary>
Friend Class MyTest
Public Sub New()
End Sub
<STAThread> _
Shared Sub Main(ByVal args() As String)
Dim test As New MyTest()
test.testSign()
test.testvalidateSign()
Console.ReadLine()
End Sub
Friend Sub testvalidateSign()
'instantiate and open the file
Dim wb As New Workbook("e:\test\digital signatures\newfile.xlsx")
'wb.IsDigitallySigned is true when the workbook is signed already.
System.Console.WriteLine(wb.IsDigitallySigned) 'True -OK
'get digitalSignature collection from workbook
Dim dsc As DigitalSignatureCollection = wb.GetDigitalSignature()
For Each ds As DigitalSignature In dsc
System.Console.WriteLine(ds.Comments) 'test for sign -OK
System.Console.WriteLine(ds.SignTime) '11/25/2010 1:22:01 PM -OK
System.Console.WriteLine(ds.IsValid) 'True -OK
Next ds
End Sub
Friend Sub testSign()
'dsc is signature collection contains one or more signature needed to sign
Dim dsc As New DigitalSignatureCollection()
'cert must contain private key, it can be contructed from cert file or windows certificate collection.
'123456 is password of cert
Dim cert As New X509Certificate2("e:\test\digital signatures\mykey2.pfx", "123456")
Dim ds As New DigitalSignature(cert, "test for sign", DateTime.Now)
dsc.Add(ds)
Dim wb As New Workbook()
'wb.SetDigitalSignature signs all signatures in dsc
wb.SetDigitalSignature(dsc)
wb.Save("e:\test\digital signatures\newfile.xlsx")
End Sub
End Class
End Namespace
執行上述代碼后,所生成的文件中包含了所分配的數字簽名的詳細信息,如下截圖:
輸出的Excel文件將帶有一個數字簽名圖標/符號。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網