* * *

Author Topic: Blowfish decrypt string  (Read 476 times)

KarenT

  • New member
  • *
  • Posts: 19
Blowfish decrypt string
« on: May 20, 2017, 01:12:22 am »
Hello,

I have a Delphi sqlite database with Blowfish encrypted strings. I am moving over to Linux-Mint and using Lazarus. Most things have gone smoothly but I am having trouble finding some example code for decrypting and encrypting the database that I used TurboPower Blowfish LockBox component.

I have looked at the Blowfish Unit in Lazarus, but unsure how to use it with Strings. Could I please get some help with this?

Code: Pascal  [Select]
  1. // This is roughly what I used in Delphi.
  2. var
  3.   aCodedStr : String;
  4.   aDecodedStr : String;
  5.   aKeyStr : String;
  6. begin
  7.   lbBF.GenerateKey(aKeyStr);
  8.   aCodedStr:=lbBF.EncryptString(aCodedStr);
  9.   tblStuff.FieldByName('cData').AsString:=aCodedStr;
  10.   // Save to Database
  11.   // do things here
  12.   // Then read back
  13.   aDecodedStr:=lbBF.DecryptString(tblStuff.FieldByName('cData').AsString);
  14.  
« Last Edit: May 20, 2017, 01:14:08 am by KarenT »

Thaddy

  • Hero Member
  • *****
  • Posts: 3421
Re: Blowfish decrypt string
« Reply #1 on: May 20, 2017, 08:10:38 am »
Why not simply use LockBox itself, because you are familiar with it? And LockBox also works in Lazarus....
https://github.com/jarto/lockbox2

You should be able to import all Delphi code and it should work as it worked in Delphi without anything else.
This particular LockBox version is 32/64 bit and win/linux/mac/bsd
« Last Edit: May 20, 2017, 09:04:16 am by Thaddy »

KarenT

  • New member
  • *
  • Posts: 19
Re: Blowfish decrypt string
« Reply #2 on: May 20, 2017, 05:04:22 pm »
Why not simply use LockBox itself, because you are familiar with it? And LockBox also works in Lazarus....
https://github.com/jarto/lockbox2

You should be able to import all Delphi code and it should work as it worked in Delphi without anything else.
This particular LockBox version is 32/64 bit and win/linux/mac/bsd

Thank you. I had searched for some Lazarus version of LockBox that might have been ported, but that did not show up. I have downloaded and will try it. My Delphi is 2007, but hopefully that will not matter, maybe just need to tweak some old code.

It will certainly will save some time as I have two other programs I need to convert that also used LockBox.

KarenT

  • New member
  • *
  • Posts: 19
Re: Blowfish decrypt string
« Reply #3 on: May 20, 2017, 05:29:07 pm »
Why not simply use LockBox itself, because you are familiar with it? And LockBox also works in Lazarus....

Thaddy, I am at a loss here. The docs say there is no Package for Lazarus and there are no examples of how to use this with Lazarus.

I have added lbCipher to the Project list as I assume that is the base Component, but I have no idea how to proceed from there.

Is there anyone who has used Lockbox2 who can give me some code examples on how to use it? I was expecting to find an .lpk file.

I am only about two weeks into using Lazarus and slowly making my way up the learning curve, but "stumped" is the word that springs to mind here.

KarenT

  • New member
  • *
  • Posts: 19
Re: Blowfish decrypt string
« Reply #4 on: May 20, 2017, 05:56:04 pm »
OK, figured it out. If anyone else needs this there is no need to add lbCipher to the Project Inspector

Code: Pascal  [Select]
  1. // Add the following to main uses clause
  2.    lbCipher, LbClass,
  3.  
  4. //In the FormCreate
  5.   lbBF:=TLbBlowfish.Create(Self);
  6.   lbBF.GenerateKey(edKey.Text);
  7.  
  8. //In the FormDestroy
  9.   lbBF.Free;
  10.  
  11. // Use the following anywhere
  12.   edDec.Text:=lbBF.DecryptString(edEnc.Text);
  13.  or
  14.   edEnc.Text:=lbBF.EncryptString(edDec.Text);
  15.  



Thaddy

  • Hero Member
  • *****
  • Posts: 3421
Re: Blowfish decrypt string
« Reply #5 on: May 20, 2017, 09:42:41 pm »
Nice to see it works  :)

KarenT

  • New member
  • *
  • Posts: 19
Re: Blowfish decrypt string
« Reply #6 on: May 21, 2017, 04:32:48 pm »
Nice to see it works  :)

It was a nice surprise to suddenly see the correctly decrypted stuff from the Delphi database.

Thanks for the help.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus