原創(chuàng)|使用教程|編輯:何家巧|2022-12-15 17:29:30.840|閱讀 310 次
概述:今天我們一起來(lái)看看使用 FastReport VCL 對(duì)文件進(jìn)行數(shù)字簽名,詳細(xì)教程如下。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
FastReport VCL是用于在軟件中集成商務(wù)智能的現(xiàn)代解決方案。它提供了可視化模板設(shè)計(jì)器,可以訪問(wèn)最受歡迎的數(shù)據(jù)源,報(bào)告引擎,預(yù)覽,將過(guò)濾器導(dǎo)出為30多種格式,并可以部署到云,Web,電子郵件和打印中。
我們很難想象沒(méi)有電子文檔管理的生活,電子文檔的文件不易丟失,易于存儲(chǔ),并且可以方便轉(zhuǎn)移。但眾所周知,只有簽署的文件才能生效。
電子簽名是保證唯一性和原創(chuàng)性的密碼,這樣可以建立明確的作者身份并保護(hù)文檔免受更改。
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;
寫完程序,讓我們繼續(xù)運(yùn)行它。
啟動(dòng)后,點(diǎn)擊“導(dǎo)出”按鈕。然后我們得到一個(gè)帶有簽名文件的簽名PDF文件:
我們應(yīng)該檢查 PDF 文件是否正確簽名。為此,打開(kāi)控制臺(tái)并輸入以下命令:
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 文件已通過(guò)簽名檢查,所以我們做到了。
因此,我們用FastReport VCL快速地得到了一個(gè)正確導(dǎo)出的PDF文件的簽名。
FastReport技術(shù)QQ群:536197826 歡迎進(jìn)群一起討論
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn