彩票走势图

Aspose.Cells电子表格指定和验证数字签名的示例

原创|其它|编辑:郝浩|2012-07-01 21:37:10.000|阅读 497 次

概述: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(&quot;e:\test\digital signatures\newfile.xlsx")

End Sub
End Class
End Namespace

执行上述代码后,所生成的文件中包含了所分配的数字签名的详细信息,如下截图:

数字签名,验证数字签名,Aspose.Cells,

输出的Excel文件将带有一个数字签名图标/符号。

数字签名,验证数字签名,Aspose.Cells,

 


(慧都控件网版权所有,转载请注明出处,否则追究法律责任)
标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn

文章转载自:慧都控件网

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP