DelphiFan Magazine

Top Menu

Main Menu

  • DELPHI
  • CODE SAMPLES
  • FIREMONKEY
  • DATABASE
  • RELEASES
  • VIDEOS
  • REVIEW
  • TECH NEWS

logo

DelphiFan Magazine

  • DELPHI
  • CODE SAMPLES
  • FIREMONKEY
  • DATABASE
  • RELEASES
  • VIDEOS
  • REVIEW
  • TECH NEWS
  • How to add a server application written in UNIGUI to startup?

  • UniGUI Expiry Link Anonymizer

  • UniGUI Add CAPTCHA to the WEB project

  • UniGui. Unique hybrid of Delphi and JS

  • How to transform a blob field into string lines (varchar) in SQL Firebird?

CODE SAMPLESDELPHI
Home›CODE SAMPLES›Use LockBox does encryption and decryption

Use LockBox does encryption and decryption

By admin
January 2, 2021
461
0
Share:

LockBox is an excellent set of open source controls. Its predecessor is TruboPower LockBox is a set of commercial controls.

LockBox decided to open source when it reached Version 2. So there is LockBox2, which is exactly the same as the previous commercial controls.

Later, someone wrote another set called LockBox3. This version is also open source, but the code is completely different and the usage is different. The open source protocol used is also different.

For the difference between LockBox2 and LockBox3, and why you want to create another one, please see here: http://lockbox.seanbdurkin.id.au/HomePage

Download here:

LockBox2:

https://github.com/TurboPack/LockBox/

LockBox3:

https://github.com/TurboPack/LockBox3

 

I tried to download the ZIP of LockBox2 and LockBox3, unzip it, and install it to Delphi 10.2 Tokyo version. I found a problem: I installed the VCL version and FMX version at the same time, but after the installation, I did not see it on the control panel. After restarting Delphi, it says that the XX package was unsuccessfully loaded during startup, and so on.

I had to uninstall the FMX version, leaving only the VCL version to successfully see the controls on the control panel of the IDE. Write an example program, drag the control over, write some test code, and pass.

The following is the test code after dragging the control over:

 

procedure TForm2.Button1Click(Sender: TObject);
var
  S: string;
begin
//This is the usage of the LockBox 2.0 control. LockBox3 is completely different.
//Here is to drag the control over.
  Lb3DES1.GenerateKey(‘abcd1234’);
  S := Lb3DES1.EncryptString(Edit1.Text);
  Memo1.Lines.Add(S);
  Memo1.Lines.Add(”);
 
  S := Lb3DES1.DecryptString(S);
  Memo1.Lines.Add(S);
end;
 
procedure TForm2.Button2Click(Sender: TObject);
var
  EncryptDataStr: string;
  DecodedStr: string;
begin
//The following is the usage of LockBox3. Codec1 is dragged over.
  Codec1.PassWord := ‘abc3455’;
  Codec1.EncryptString(Edit1.Text, EncryptDataStr, TEncoding.UTF8);
  Memo1.Lines.Add(EncryptDataStr);
 
  Codec1.DecryptString(DecodedStr, EncryptDataStr, TEncoding.UTF8);
 
  Memo1.Lines.Add(DecodedStr);
 
  Memo1.Lines.Add(”);
end;
If you don’t drag the control, you can also use the code to create the object at runtime and use it.
The following is an example code written with LockBox3, encrypted:
procedure TForm3.Button1Click(Sender: TObject);
var
 Codec1: TCodec;
 CryptographicLibrary1: TCryptographicLibrary;
 sEncryptData : String;
begin
  Codec1 := TCodec.Create( nil);
  CryptographicLibrary1 := TCryptographicLibrary.Create( nil);
  try
    Codec1.CryptoLibrary  := CryptographicLibrary1;
    Codec1.StreamCipherId := uTPLb_Constants.BlockCipher_ProgId;
    Codec1.BlockCipherId  := ‘native.AES-256’;
    Codec1.ChainModeId    := uTPLb_Constants.CBC_ProgId;
    Codec1.Password := ‘This is a test for AES’;
    Codec1.EncryptString(Edit1.Text, sEncryptData, TEncoding.UTF8);
    Edit2.Text := sEncryptData;
  finally
    Codec1.Free;
    CryptographicLibrary1.Free;
  end;
end;
The following is decryption:
procedure TForm3.Button2Click(Sender: TObject
var
 Codec1: TCodec;
 CryptographicLibrary1: TCryptographicLibrary;
 sData : String;
begin
  Codec1 := TCodec.Create( nil);
  CryptographicLibrary1 := TCryptographicLibrary.Create( nil);
  try
    Codec1.CryptoLibrary  := CryptographicLibrary1;
    Codec1.StreamCipherId := uTPLb_Constants.BlockCipher_ProgId;
    Codec1.BlockCipherId  := ‘native.AES-256’;
    Codec1.ChainModeId    := uTPLb_Constants.CBC_ProgId;
    Codec1.Password := ‘This is a test for AES’;
    Codec1.DecryptString(sData, Edit2.Text, TEncoding.UTF8);
    Edit3.Text := sData;
  finally
    Codec1.Free;
    CryptographicLibrary1.Free;
  end;
end;
It seems that the use of LockBox3 is slightly more troublesome than the use of LockBox2.
Tagscalculate md5decryptiondelphidelphi md5encryptionLockBoxmd5
Previous Article

Use Windows API (WinCrypt) to calculate the ...

Next Article

Where to download OpenSSL binaries?

0
Shares
  • 0
  • +
  • 0
  • 0
  • 0
  • 0

admin

Related articles More from author

  • CODE SAMPLESDELPHI

    Rapidly Use Delphi FireDAC In A Multithreaded Environment With The FireDAC.Pooling Sample

    September 14, 2020
    By admin
  • CODE SAMPLESDELPHI

    Delphi View DPR file

    January 1, 2021
    By admin
  • CODE SAMPLESDELPHI

    Good code samples for cxGrid Part2

    October 26, 2020
    By admin
  • CODE SAMPLESDELPHI

    How to put a DateTimePicker in the DBGrid?

    January 3, 2021
    By admin
  • CODE SAMPLESDELPHI

    How does Delphi handle different types of files

    November 19, 2020
    By admin
  • DELPHIRELEASES

    Bold for Delphi is Open Source

    September 21, 2020
    By admin

Leave a reply Cancel reply

You may interested

  • DELPHIRELEASES

    FastReport 6.8 VCL Released

  • CODE SAMPLESDELPHI

    View the output function list of DLL

  • CODE SAMPLESDELPHI

    Internationalizing your application in Delphi

  • LATEST REVIEWS

  • TOP REVIEWS

Timeline

  • January 27, 2021

    How to add a server application written in UNIGUI to startup?

  • January 27, 2021

    UniGUI Expiry Link Anonymizer

  • January 26, 2021

    UniGUI Add CAPTCHA to the WEB project

  • January 26, 2021

    UniGui. Unique hybrid of Delphi and JS

  • January 13, 2021

    How to transform a blob field into string lines (varchar) in SQL Firebird?

Latest Comments

Find us on Facebook

Follow Us on Instagram

logo

Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.

About us

  • 660 Pennsylvania Avenue Southeast #100 Washington, DC 20003
  • 0123456789
  • adsdelphi@gmail.com
  • Recent

  • Popular

  • Comments

  • How to add a server application written in UNIGUI to startup?

    By admin
    January 27, 2021
  • UniGUI Expiry Link Anonymizer

    By admin
    January 27, 2021
  • UniGUI Add CAPTCHA to the WEB project

    By admin
    January 26, 2021
  • UniGui. Unique hybrid of Delphi and JS

    By admin
    January 26, 2021
  • How to add a server application written in UNIGUI to startup?

    By admin
    January 27, 2021
  • Amazing Cross Platform Email App Sample In Delphi 10.4.1 FireMonkey For Android And IOS

    By admin
    August 13, 2020
  • Critical Update Available For Delphi FireMonkey 10.4.1 On Android, IOS, OSX, Windows, And Linux

    By admin
    September 4, 2020
  • Setting up the IDE for your first Android Application in Delphi

    By admin
    September 7, 2020

Follow us

Find us on Facebook

© Copyright Delphifan Forum. All rights reserved.