FastReport中国社区FastReport联系电话 联系电话:023-68661681

如何使用 FastReport VCL 对文件进行数字签名?

来源:   发布时间:2022-12-19   浏览:次

FastReport VCL是用于在软件中集成商务智能的现代解决方案。它提供了可视化模板设计器,可以访问最受欢迎的数据源,报告引擎,预览,将过滤器导出为30多种格式,并可以部署到云,Web,电子邮件和打印中。

FastReport VCL最新版下载

我们很难想象没有电子文档管理的生活,电子文档的文件不易丢失,易于存储,并且可以方便转移。但众所周知,只有签署的文件才能生效。电子签名是保证唯一性和原创性的密码,这样可以建立明确的作者身份并保护文档免受更改。
但是,对每个生成的 PDF 文件进行签名可能非常耗时。如果您有上千个或更多生成的文件怎么办——您还要手动签署它们吗?当然不是。FastReport VCL 可以帮助您对生成的文件进行签名。接下来,我们将演示数字签名的示例。
为清楚起见,我们将使用一个小型应用程序将文件导出为 PDF 并对其进行签名。

procedure TForm1.Button1Click(Sender: TObject); const  FR3FileName = 'Signatures.fr3'; var  PDFExport: TfrxPDFExport;  Report: TfrxReport; begin  Report := TfrxReport.Create(nil);  try  Report.LoadFromFile(FR3FileName);  Report.PrepareReport; // upload and prepare a report    PDFExport := TfrxPDFExport.Create(nil);  try  PDFExport.Report := Report;  PDFExport.ShowDialog := False;      PDFExport.FileName := ExtractFileName(FR3FileName) + '.pdf';  Report.Export(PDFExport); // export the report  SignExport(PDFExport); // sign the file  finally  PDFExport.Free;  end;  finally  Report.Free;  end; end;   procedure SignExport(PDFExport: TfrxPDFExport); const  CertificatePath = 'JaneDoe.pfx'; // The name of our certificate  PasCert = '123'; // certificate password var  Lookup: TCertificateStoreLookup;  FS: TfrxFileSignature;  FSO: Integer; begin  Lookup := TCertificateStoreLookup.Create;  Lookup.IgnoreCase := true;  Lookup.CertificatePath := CertificatePath;    FSO := FileSignatureOptions(  true, // Detached = true Signature in a detached file  false, // Chain = false Certificate chain  false, // OnlyGOST= true GOST certificate  true, // DebugLog = true Debugging Information  true); // PFX = false (true) indicates that the certificate should be searched in the pfx/p12 file.  At the same time, the file name and, possibly, the password must be specified.    FS := TfrxFileSignature.Create(  Lookup,  PDFExport.FileName, // PDF file name  PDFExport.FileName + '.sig', // Name of the generated signature  AnsiString(PasCert),  FSO);    FS.Sign;  FS.Free;  Lookup.Free; end;

写完程序,让我们继续运行它。

启动后,点击“导出”按钮。然后我们得到一个带有签名文件的签名PDF文件:

我们应该检查 PDF 文件是否正确签名。为此,打开控制台并输入以下命令:

openssl pkcs12 -in JohnDoe.pfx -out JohnDoe.pem

我们输入密码并使用以下命令检查后:

openssl smime -verify  -binary  -inform DER -in Signatures.fr3.pdf.sig -content Signatures.fr3.pdf  -certfile JohnDoe.pem -nointern  -noverify  1 >  / dev / null

此屏幕截图显示 PDF 文件已通过签名检查,所以我们做到了。
因此,我们用FastReport VCL快速地得到了一个正确导出的PDF文件的签名。

FastReport技术QQ群:536197826      欢迎进群一起讨论

本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:FastReport控件中文网 [https://www.fastreportcn.com/]
本文地址:https://www.fastreportcn.com/post/3421.html

联系我们
  • 重庆总部 023-68661681
购买
  • sales@evget.com
合作
  • business@evget.com


在线
客服
微信
QQ 电话
023-68661681
返回
顶部