Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Use Base64 RSA Key to Encrypt
See more RSA Examples
Loads a Base64 RSA key and uses it to encrypt a string, returning the result in base64.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.Rsa,
Chilkat.PublicKey;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
pubkey: TPublicKey;
rsa: TRsa;
encryptedStr: string;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
pubkey := TPublicKey.Create;
success := pubkey.LoadBase64('MIICdgIBADA ... A9PXLk+j5A==');
if (success = False) then
begin
WriteLn(pubkey.LastErrorText);
Exit;
end;
rsa := TRsa.Create;
success := rsa.UsePublicKey(pubkey);
if (success = False) then
begin
WriteLn(rsa.LastErrorText);
Exit;
end;
rsa.EncodingMode := 'base64';
encryptedStr := rsa.EncryptStringENC('12345678',False);
WriteLn(encryptedStr);
pubkey.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.