文件上的数字签名 [英] Digital signature on documents

查看:107
本文介绍了文件上的数字签名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,



我有一个数字签名(.pfx文件)。我想将此数字签名作为可见签名添加到文档中,该文档可以是以下任何格式 - csv,word,excel或PDF。有人可以帮我在c#.net窗体上实现吗?



感谢你...



我的尝试:



我能够成功将签名附加到pdf。但是无法将其附加到word和excel ...请帮助



I have a digital signature (.pfx file) with me. I want to add this digital signature as a visible signature to a document which could be of any of these following formats- csv, word, excel or PDF. Can anybody help me to implement this on c# .net windows forms?

Thanking you...

What I have tried:

I am able to successfully attach a signature to pdf. but not able to attach the same to word and excel... please help

推荐答案

private void CreateNewPage()
  {
      object missing = System.Reflection.Missing.Value;
      object fileName = @"F:\Doc\test.docx";
      object readOnly = false;
      object isVisible = true;

      //Start Word and open a document.
      Microsoft.Office.Interop.Word._Application oWord;
      Microsoft.Office.Interop.Word._Document oDoc;
      oWord = new Microsoft.Office.Interop.Word.Application();
      oWord.Visible = true;

      oDoc = oWord.Documents.Open(ref fileName, ref missing, ref readOnly,
          ref missing, ref missing, ref missing, ref missing, ref missing,
          ref missing, ref missing, ref missing, ref isVisible, ref missing,
          ref missing, ref missing, ref missing);

      //  var numberOfPages = oDoc.ComputeStatistics(Word.WdStatistic.wdStatisticPages, false);

      object oEndOfDoc = "\\endofdoc";
      object paramNextPage = Microsoft.Office.Interop.Word.WdBreakType.wdSectionBreakNextPage;

      oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range.InsertBreak(ref paramNextPage);
      //Insert a page break
      object breakPage = Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;


      object saveOption = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
      object originalFormat = Microsoft.Office.Interop.Word.WdOriginalFormat.wdOriginalDocumentFormat;
      object routeDocument = false;

      object what = Microsoft.Office.Interop.Word.WdGoToItem.wdGoToPage;
      object which = Microsoft.Office.Interop.Word.WdGoToDirection.wdGoToLast;
      object count = 3;

      oWord.Selection.GoTo(ref what, ref which, ref count, ref missing);

      object sigID = "{00000000-0000-0000-0000-000000000000}";


      try
      {
          oWord.Activate();

          SignatureSet signatureSet = oWord.ActiveDocument.Signatures;
          // signatureSet.ShowSignaturesPane = false;
          Signature objSignature = signatureSet.AddSignatureLine(sigID);
          objSignature.Setup.SuggestedSigner = "docSigner";
          objSignature.Setup.SuggestedSignerEmail = "abc@xyz.com";
          objSignature.Setup.ShowSignDate = true;
          //  dynamic shape = objSignature.SignatureLineShape;
      }
      catch (Exception ex) { MessageBox.Show(ex.Message); }

      oWord.Documents.Save();
      oWord.Quit();

      try
      {
          Marshal.ReleaseComObject(oWord);
      }
      catch (Exception e) { MessageBox.Show(e.Message); }
  }


这篇关于文件上的数字签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆