300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 如何使用 FastReport VCL 对文件进行数字签名?

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

时间:2021-04-05 10:11:35

相关推荐

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

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

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

此屏幕截图显示 PDF 文件已通过签名检查,所以我们做到了。

因此,我们用FastReport VCLFastReport VCL快速地得到了一个正确导出的PDF文件的签名。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。