码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Word控件Spire.Doc 【加密解密】教程(四):在 C# 中为 Word 添加数字签名


    本文演示了如何使用 Spire.Doc 将数字签名添加到 Word 文档。

    Spire.Doc for.NET 最新下载icon-default.png?t=M666https://www.evget.com/product/3368/download

    Spire.Doc 为我们提供了以下方法来为 Word 文档添加数字签名:

    • public void SaveToFile(string fileName, FileFormat fileFormat, byte[] certificateData, string securePassword);
    • public void SaveToFile(string fileName, FileFormat fileFormat, string certificatePath, string securePassword);
    • public void SaveToStream(Stream stream, FileFormat fileFormat, byte[] certificateData, string securePassword);
    • public void SaveToStream(Stream stream, FileFormat fileFormat, string certificatePath, string securePassword);
    • public static byte[] Sign(Stream sourceStream, byte[] certificateData, string securePassword);
    • public static byte[] Sign(Stream sourceStream, string certificatePath, string securePassword);

    在下面的示例中,我们将看到如何将数字签名添加到 Word 文档,并使用带有 Document 对象的SaveToFile方法将结果保存到文件中。

    //Load the Word document
    Document doc = new Document("sample.docx");
    //Sign the document with certificate and save to file
    doc.SaveToFile("AddDigitalSignature.docx", FileFormat.Docx2013, "gary.pfx", "e-iceblue");
    

    我们还可以将数字签名添加到 Word 文档,并使用带有 Document 对象的SaveToStream方法将结果保存到流中 。

    //Load the Word document
    Document doc = new Document("sample.docx");
    //Create a FileStream
    FileStream fs = new FileStream();
    //Sign the document with certificate and save to stream
    doc.SaveToStream(fs, FileFormat.Docx2013, "gary.pfx", "e-iceblue");
    fs.Flush();
    

    下面的示例演示如何使用带有 Document 类的 Sign 方法将数字签名添加到 Word 文档。

    //Read the Word document into a FileStream
    FileStream fs = File.OpenRead("sample.docx");
    //Sign the document using Sign method with Document class
    byte[] result = Document.Sign(fs, "gary.pfx", "e-iceblue");
    File.WriteAllBytes("AddDigitalSignature.docx", result);
    fs.Flush();
    

    输出文件:

  • 相关阅读:
    golang context原理
    Linux系统命令——文件与文件目录管理
    数据解析——Jsonpath
    Spark - RDD 的分区和Shuffle
    OSI七层模型&TCP/IP四层&面试高频考点
    【MySql】MySQL中InnoDB支持的四种事务隔离级别名称,以及区别和能解决的问题。
    linux_day04
    c/c++断言
    基于Spring Boot 3 + Spring Security6 + JWT + Redis实现登录、token身份认证
    docker上面部署nginx-waf 防火墙“modsecurity”,使用CRS规则,搭建WEB应用防火墙
  • 原文地址:https://blog.csdn.net/m0_67129275/article/details/126305498
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号