Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Store Encrypted String in a ClientDataSet...



Permlink Replies: 6 - Last Post: Apr 10, 2017 8:12 PM Last Post By: Thiago Silva
Thiago Silva


Posts: 37
Registered: 12/20/04
Store Encrypted String in a ClientDataSet...
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 3, 2017 5:07 PM
Hi Everyone,

I am trying to store a encrypted string in a string field inside a clientdataset, but when I assign the value the data is broken. For example, I have a string: "my dog is black and bark alot" then I encryt the string and when store the encrypted contents and decrypted after the string is "my dog" only. Any char is broke the string! How do I store correctly the string? Is it possible? My App is base on DataSnap.

Thanks alot!

Thiago.
Matthew Vesperman

Posts: 7
Registered: 1/11/01
Re: Store Encrypted String in a ClientDataSet...
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 3, 2017 5:35 PM   in response to: Thiago Silva in response to: Thiago Silva
Thiago Silva wrote:
Hi Everyone,

I am trying to store a encrypted string in a string field inside a clientdataset, but when I assign the value the data is broken. For example, I have a string: "my dog is black and bark alot" then I encryt the string and when store the encrypted contents and decrypted after the string is "my dog" only. Any char is broke the string! How do I store correctly the string? Is it possible? My App is base on DataSnap.

Thanks alot!

Thiago.

It sounds like your database field is too small and the data is being truncated.

Create a demo where your string is encrypted. Then display the length of the encrypted string. If your database field is smaller than the encrypted string length then it is being truncated.

If that is not the problem then try to encrypt/decrypt without the data going to the database first.

Additionally, posting a small demo program would help debug the issue for you.
Thiago Silva


Posts: 37
Registered: 12/20/04
Re: Store Encrypted String in a ClientDataSet...
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 3, 2017 5:44 PM   in response to: Matthew Vesperman in response to: Matthew Vesperman
Thank you Matthew!

The field size is 29 and the encrypted string is 29 is the same size but when I assign the contents to the field like this: DataSet.FieldByName('FIELD').AsString := 'Encrypted String' somechar in encrypted string broken the contents. The encrypted string is a very simple 128 bits encrypting. There is a special char in the string causing this behavor.

Any suggestion? How to store correctly? I can send a demo but how to send to you?

Regards,

Thiago.

Edited by: Thiago Silva on Apr 3, 2017 5:45 PM
Jeff Overcash (...

Posts: 1,529
Registered: 9/23/99
Re: Store Encrypted String in a ClientDataSet... [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 3, 2017 9:12 PM   in response to: Thiago Silva in response to: Thiago Silva
Thiago Silva wrote:
Thank you Matthew!

The field size is 29 and the encrypted string is 29 is the same size but when I assign the contents to the field like this: DataSet.FieldByName('FIELD').AsString := 'Encrypted String' somechar in encrypted string broken the contents. The encrypted string is a very simple 128 bits encrypting. There is a special char in the string causing this behavor.

Any suggestion? How to store correctly? I can send a demo but how to send to you?

Regards,

Thiago.

Edited by: Thiago Silva on Apr 3, 2017 5:45 PM

Once encrypted it is no longer a string and should no longer be treated as a
string (ie storing in a string column). either Base64 encode it so it is again a
string or store it in a blob.

--
Jeff Overcash (TeamB)
(Please do not email me directly unless asked. Thank You)
Learning is finding out what you already know. Doing is demonstrating that you
know it. Teaching is reminding others that they know it as well as you. We are
all leaners, doers, teachers. (R Bach)
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: Store Encrypted String in a ClientDataSet... [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 4, 2017 10:30 AM   in response to: Jeff Overcash (... in response to: Jeff Overcash (...
Am 04.04.2017 um 06:12 schrieb Jeff Overcash (TeamB):
Thiago Silva wrote:
Thank you Matthew!

The field size is 29 and the encrypted string is 29 is the same size but when I assign the contents to the field like this: DataSet.FieldByName('FIELD').AsString := 'Encrypted String' somechar in encrypted string broken the contents. The encrypted string is a very simple 128 bits encrypting. There is a special char in the string causing this behavor.

Any suggestion? How to store correctly? I can send a demo but how to send to you?

Regards,

Thiago.

Edited by: Thiago Silva on Apr 3, 2017 5:45 PM

Once encrypted it is no longer a string and should no longer be treated as a
string (ie storing in a string column). either Base64 encode it so it is again a
string or store it in a blob.

I agree or convert it to a hexadecimal representation. Needs double
number of chars but would work as well.

RTLs IntToStr and StrToInt can deal with such conversions for single
bytes. (for StrToInt you need to prefix this with '0x' so it recognizes
it as hex.

Greetings

Markus
Matthew Vesperman

Posts: 7
Registered: 1/11/01
Re: Store Encrypted String in a ClientDataSet... [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 5, 2017 8:16 AM   in response to: Jeff Overcash (... in response to: Jeff Overcash (...
Jeff Overcash (TeamB) wrote:
Thiago Silva wrote:
Thank you Matthew!

The field size is 29 and the encrypted string is 29 is the same size but when I assign the contents to the field like this: DataSet.FieldByName('FIELD').AsString := 'Encrypted String' somechar in encrypted string broken the contents. The encrypted string is a very simple 128 bits encrypting. There is a special char in the string causing this behavor.

Any suggestion? How to store correctly? I can send a demo but how to send to you?

Regards,

Thiago.

Edited by: Thiago Silva on Apr 3, 2017 5:45 PM

Once encrypted it is no longer a string and should no longer be treated as a
string (ie storing in a string column). either Base64 encode it so it is again a
string or store it in a blob.

--
Jeff Overcash (TeamB)
(Please do not email me directly unless asked. Thank You)
Learning is finding out what you already know. Doing is demonstrating that you
know it. Teaching is reminding others that they know it as well as you. We are
all leaners, doers, teachers. (R Bach)

Both Jeff and Marcus are correct. I had forgotten that you need to encode it back to a string (I use Base64, but converting to hex works too) when you store it. Just remember you have to decode it before decrypting it.
Thiago Silva


Posts: 37
Registered: 12/20/04
Re: Store Encrypted String in a ClientDataSet... [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 10, 2017 8:12 PM   in response to: Matthew Vesperman in response to: Matthew Vesperman
Matthew Vesperman wrote:
Jeff Overcash (TeamB) wrote:
Thiago Silva wrote:
Thank you Matthew!

The field size is 29 and the encrypted string is 29 is the same size but when I assign the contents to the field like this: DataSet.FieldByName('FIELD').AsString := 'Encrypted String' somechar in encrypted string broken the contents. The encrypted string is a very simple 128 bits encrypting. There is a special char in the string causing this behavor.

Any suggestion? How to store correctly? I can send a demo but how to send to you?

Regards,

Thiago.

Edited by: Thiago Silva on Apr 3, 2017 5:45 PM

Once encrypted it is no longer a string and should no longer be treated as a
string (ie storing in a string column). either Base64 encode it so it is again a
string or store it in a blob.

--
Jeff Overcash (TeamB)
(Please do not email me directly unless asked. Thank You)
Learning is finding out what you already know. Doing is demonstrating that you
know it. Teaching is reminding others that they know it as well as you. We are
all leaners, doers, teachers. (R Bach)

Both Jeff and Marcus are correct. I had forgotten that you need to encode it back to a string (I use Base64, but converting to hex works too) when you store it. Just remember you have to decode it before decrypting it.

Thank you very much!
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02