Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Duplicate openssl dgst -sha256 -verify pubKey.pem -signature signature.sig in.dat
See more OpenSSL Examples
Demonstrates how to duplicate this OpenSSL command:openssl dgst -sha256 -verify pubKey.pem -signature signature.sig in.datThe in.dat file contains the original data that was signed, and can contain text or binary data of any type. The above OpenSSL command does the following:
- Creates a SHA256 digest of the contents of the input file.
- Verifies the SHA256 digest using the public key.
Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.BinData,
Chilkat.Rsa,
Chilkat.PublicKey;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
pubKey: TPublicKey;
bdFileData: TBinData;
bdSig: TBinData;
rsa: TRsa;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
pubKey := TPublicKey.Create;
// Load the public key from an PEM file:
success := pubKey.LoadFromFile('pubKey.pem');
if (success = False) then
begin
WriteLn(pubKey.LastErrorText);
Exit;
end;
// Load the data of the original file that was signed.
bdFileData := TBinData.Create;
success := bdFileData.LoadFile('in.dat');
// Load the signature.
bdSig := TBinData.Create;
success := bdSig.LoadFile('signature.sig');
rsa := TRsa.Create;
// Import the public key into the RSA component:
success := rsa.UsePublicKey(pubKey);
if (success = False) then
begin
WriteLn(rsa.LastErrorText);
Exit;
end;
// OpenSSL uses big-endian.
rsa.LittleEndian := False;
success := rsa.VerifyBd(bdFileData,'sha256',bdSig);
if (success <> True) then
begin
WriteLn(rsa.LastErrorText);
WriteLn('The signature was invalid.');
Exit;
end;
WriteLn('The signature was verified.');
pubKey.Free;
bdFileData.Free;
bdSig.Free;
rsa.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.