Recent

Author Topic: Blowfish and SQLite: some errors.  (Read 3258 times)

GAN

  • Sr. Member
  • ****
  • Posts: 370
Blowfish and SQLite: some errors.
« on: February 26, 2018, 12:56:26 am »
Aprox. 95% of strings are encrypted, saved and load OK. But with some words I receive an empty string or an error. Demo proyect is attached.

Works fine with:
)(@3849lñ.kd88hoiujhiou
jkgakglaghiasughuiao
jaui oike
jaui oike27
jauioike27
tango272
raven27

I receive empty strings with;
gaston27
gasto27
mal

Error with: tango27

Note: If you add a space at the end of the string before encrypt it, then works fine 100%, so I could solve this problem adding a space to write and removing it after read it.

The question is: Why?

Best regards.
Lazarus 2.0.8 FPC 3.0.4 Linux Mint Mate 19.3
Zeos 7̶.̶2̶.̶6̶ 7.1.3a-stable - Sqlite 3.32.3 - LazReport

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Blowfish and SQLite: some errors.
« Reply #1 on: February 26, 2018, 01:29:56 am »
Most likely that's a known bug. You need to free the encodings TEncoding.FreeEncodings. More about it in the 3rd page of this thread.

GAN

  • Sr. Member
  • ****
  • Posts: 370
Re: Blowfish and SQLite: some errors.
« Reply #2 on: February 26, 2018, 01:53:16 am »
It didn't work. Note that the encryption/decryption in memory works well always, the problem only arises when reading the database. Yes I read the thread, in fact I based in your code;)
Lazarus 2.0.8 FPC 3.0.4 Linux Mint Mate 19.3
Zeos 7̶.̶2̶.̶6̶ 7.1.3a-stable - Sqlite 3.32.3 - LazReport

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Blowfish and SQLite: some errors.
« Reply #3 on: February 26, 2018, 04:24:00 am »
I just saw your code. UTF8 has a specific format. That format gets destroyed after encryption. You need to encode the encrypted string into some textual form again like base64, as in the link above.

GAN

  • Sr. Member
  • ****
  • Posts: 370
Re: Blowfish and SQLite: some errors.
« Reply #4 on: February 27, 2018, 03:25:16 am »
I've tried everything, but saving and reading encrypted text in SQLIte seems impossible and I don't know if this is possible because I have found almost nothing on the Internet.
Thanks for your help, I've learned a little bit more about encryption.

Best regards.
Lazarus 2.0.8 FPC 3.0.4 Linux Mint Mate 19.3
Zeos 7̶.̶2̶.̶6̶ 7.1.3a-stable - Sqlite 3.32.3 - LazReport

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Blowfish and SQLite: some errors.
« Reply #5 on: February 27, 2018, 03:43:52 am »
Try to add base64 unit to your uses section:
Code: Pascal  [Select][+][-]
  1. uses
  2.    bases64;

At the end of Encriptar function add:
Code: Pascal  [Select][+][-]
  1.   Result := EncodeStringBase64(Result);

At the end of DesEncriptar function add:
Code: Pascal  [Select][+][-]
  1.   Result := DecodeStringBase64(Result);

Just to confirm, what text do you get for TEncoding.Default.EncodingName?

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: Blowfish and SQLite: some errors.
« Reply #6 on: February 27, 2018, 05:03:02 am »
have you tried moving strings into a RAWByteString and present those to the
encrypt , decrypt ?
 
  Also you could try using Widestrings..
The only true wisdom is knowing you know nothing

GAN

  • Sr. Member
  • ****
  • Posts: 370
Re: Blowfish and SQLite: some errors.
« Reply #7 on: February 27, 2018, 05:08:55 am »
have you tried moving strings into a RAWByteString and present those to the
encrypt , decrypt ?
 
  Also you could try using Widestrings..


Yes.

Try to add base64 unit to your uses section:
Code: Pascal  [Select][+][-]
  1. uses
  2.    bases64;

Yes, I did.

Quote
At the end of Encriptar function add:
Code: Pascal  [Select][+][-]
  1.   Result := EncodeStringBase64(Result);

At the end of DesEncriptar function add:
Code: Pascal  [Select][+][-]
  1.   Result := DecodeStringBase64(Result);

I've tried too.

Quote
Just to confirm, what text do you get for TEncoding.Default.EncodingName?

65001

Now I'm testing with a binary file, because I'm sure the lock is SQLite.
Lazarus 2.0.8 FPC 3.0.4 Linux Mint Mate 19.3
Zeos 7̶.̶2̶.̶6̶ 7.1.3a-stable - Sqlite 3.32.3 - LazReport

 

TinyPortal © 2005-2018