![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Delphi DLL) Verfies an RSA SignatureSee more Apple Keychain ExamplesVerifies an RSA signature against the original data.Note: This example requires Chilkat v11.0.0 or greater.
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, BinData, Rsa, PublicKey; ... procedure TForm1.Button1Click(Sender: TObject); var success: Boolean; bd: HCkBinData; i: Integer; bdSig: HCkBinData; pubKey: HCkPublicKey; rsa: HCkRsa; begin success := False; // The following data was signed by the following example: // RSA Sign using a Private Key on a USB Token or Smartcard bd := CkBinData_Create(); for i := 0 to 100 do begin CkBinData_AppendEncoded(bd,'000102030405060708090A0B0C0D0E0F','hex'); end; // Load the signature bdSig := CkBinData_Create(); success := CkBinData_LoadFile(bdSig,'rsaSignatures/test1.sig'); if (success = False) then begin Memo1.Lines.Add('Failed to load the RSA signature'); Exit; end; // Get the public key to be used for signature verification. pubKey := CkPublicKey_Create(); success := CkPublicKey_LoadFromFile(pubKey,'rsaKeys/chilkat-rsa-2048.pem'); if (success = False) then begin Memo1.Lines.Add(CkPublicKey__lastErrorText(pubKey)); Exit; end; rsa := CkRsa_Create(); CkRsa_UsePublicKey(rsa,pubKey); // Verify the hash of the data against the signature. // We pass in the original data. Internally, the hash is generated // and used to validate the signature. // Validating the RSA signature means two things: // (1) the original data is exactly what was signed, and // (2) it was signed by the owner of the RSA private key. success := CkRsa_VerifyBd(rsa,bd,'sha256',bdSig); if (success = False) then begin Memo1.Lines.Add(CkRsa__lastErrorText(rsa)); Memo1.Lines.Add('Signature invalid.'); end else begin Memo1.Lines.Add('Signature valid.'); end; CkBinData_Dispose(bd); CkBinData_Dispose(bdSig); CkPublicKey_Dispose(pubKey); CkRsa_Dispose(rsa); end; |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.