Encrypt/Decrypt with AES to dbf table

Xbase++ 2.0 Build 554 or later
Message
Author
Kristie Wilbanks
Posts: 4
Joined: Wed Dec 11, 2019 7:18 am

Encrypt/Decrypt with AES to dbf table

#1 Post by Kristie Wilbanks »

I have a problem decrypting a field that I encrypted and saved to a dbf. Encrypting and Decrypting work perfectly if I do not save it to a table. I have worked up a project based on the sample in exp20\Samples\Encrypt and attached it. Has anyone experienced this issue or have an idea what I might be doing wrong? Here is a snippet of the sample I worked up. Any help would be appreciated- Thank you

PROCEDURE MAIN()

LOCAL cKey := 'Now Is The Time For All Good Men To Come To the Aid of Their Country'
LOCAL cEncryptedString, cDecryptedString, CustNumber
cKey := Substr(cKey,1,32)
? cKey

SET DEFAULT TO .\DATA
USE CUSTOMER
//encrypt the customer number from Customer Table
CustNumber:= Cust_nmbr
cEncryptedString := Encrypt(CustNumber,cKey)

? Trim(cEncryptedString), Len(cEncryptedString),"Encrypted Cust Nmb"

DBRLOCK()
REPLACE Bill_name with Trim(cEncryptedString)
UNLOCK

//this works ->cDecryptedString := Trim(Decrypt( cEncryptedString, cKey ))
?Bill_name, Len(trim(Bill_Name)), "Bill_Name"
//this does not work
cDecryptedString := Decrypt( Trim(Bill_name), cKey )
? cDecryptedString, Len(cDecryptedString) , "Decrypted String from File"
Attachments
ENCRYPTtoDB.zip
(103.58 KiB) Downloaded 305 times

Victorio
Posts: 540
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: Encrypt/Decrypt with AES to dbf table

#2 Post by Victorio »

Hi, encrypted string need more space than source string.
Have you enought field size ?

User avatar
rdonnay
Site Admin
Posts: 4183
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Encrypt/Decrypt with AES to dbf table

#3 Post by rdonnay »

Encrypting creates high-order characters (higher than chr(128)).
Some databases, like DBF, cannot store those characters correctly.
Whenever I need to store encrypted data in a database, I first convert it to hexidecimal.

cHexString := DC_Var2HexString( cEncryptedString )
MYDATA->mypassword := cHexString

To convert it back:

cHexString := MYDATA->mypassword
cEncryptedString := DC_HexString2Var( cHexString )

If you don't own eXpress++, there are functions in Xbase tools for this.
BTW - A hexidecimal string is always 2x longer so the field length of the table must accomodate the longer length.
The eXpress train is coming - and it has more cars.

Dian
Posts: 21
Joined: Tue Feb 02, 2010 8:36 am
Location: Midland Texas

Re: Encrypt/Decrypt with AES to dbf table

#4 Post by Dian »

Thanks Roger, we will give that a try. Kristie is working with me and will be taking over for me when I retire in the next month or so. You might remember her from when we first started using express back in 200 or so. Thanks for all of your help over the years.

Dian
Avatar Systems

Kristie Wilbanks
Posts: 4
Joined: Wed Dec 11, 2019 7:18 am

Re: Encrypt/Decrypt with AES to dbf table

#5 Post by Kristie Wilbanks »

Thank you very much, that resolved my issue!

bwolfsohn
Posts: 618
Joined: Thu Jan 28, 2010 7:07 am
Location: Alachua, Florida USA
Contact:

Re: Encrypt/Decrypt with AES to dbf table

#6 Post by bwolfsohn »

Dian wrote:first started using express back in 200 or so.
Dian
Avatar Systems
Roger's old, but not THAT old :banana-dreads:

was this with the Clipper Winter/199 version ??

We'll be here all week folks.. don't forget to tip your waitstaff..
Brian Wolfsohn
Retired and traveling around the country to music festivals in my RV.
OOPS.. Corona Virus, so NOT travelling around the country right now...
http://www.breadmanrises.com
FB travel group: The Breadman Rises

User avatar
rdonnay
Site Admin
Posts: 4183
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Encrypt/Decrypt with AES to dbf table

#7 Post by rdonnay »

Roger's old, but not THAT old :banana-dreads:
Have you forgotten that I was the guy who brought Clipper development out of the stone age?

The year 200 was about 2200 years more advanced than the end of the stone age.

Since then, I have been bringing Xbase++ out of the medieval age.
Actually, Dian and I have been working together since 199.

I'm way older than anyone could imagine.
stoneage.jpg
stoneage.jpg (307.75 KiB) Viewed 4293 times
The eXpress train is coming - and it has more cars.

bwolfsohn
Posts: 618
Joined: Thu Jan 28, 2010 7:07 am
Location: Alachua, Florida USA
Contact:

Re: Encrypt/Decrypt with AES to dbf table

#8 Post by bwolfsohn »

rdonnay wrote:
Roger's old, but not THAT old :banana-dreads:
Have you forgotten that I was the guy who brought Clipper development out of the stone age?
stoneage.jpg
No, i haven't forgotten.. As a matter of fact, newbie, i was the guy who was sitting at the bar the first time you walked into the dBase lounge.. :lol: :lol:

(ok, your turn.. :) )
Brian Wolfsohn
Retired and traveling around the country to music festivals in my RV.
OOPS.. Corona Virus, so NOT travelling around the country right now...
http://www.breadmanrises.com
FB travel group: The Breadman Rises

User avatar
rdonnay
Site Admin
Posts: 4183
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Encrypt/Decrypt with AES to dbf table

#9 Post by rdonnay »

you walked into the dBase lounge
Ah yes.

I recall you were drinking a glass of dBase-2 tomato juice.

I offered to spice it up for you with some Clipper vodka, Tabasco and worcestershire.

You said - "I don't compile, I'm on the wagon" :angry-extinguishflame:
The eXpress train is coming - and it has more cars.

bwolfsohn
Posts: 618
Joined: Thu Jan 28, 2010 7:07 am
Location: Alachua, Florida USA
Contact:

Re: Encrypt/Decrypt with AES to dbf table

#10 Post by bwolfsohn »

rdonnay wrote:
you walked into the dBase lounge
Ah yes.

I recall you were drinking a glass of dBase-2 tomato juice.

I offered to spice it up for you with some Clipper vodka, Tabasco and worcestershire.

You said - "I don't compile, I'm on the wagon" :angry-extinguishflame:
And then you said:

"Try compiling... The first one's free" :happy-jumpeveryone:
Brian Wolfsohn
Retired and traveling around the country to music festivals in my RV.
OOPS.. Corona Virus, so NOT travelling around the country right now...
http://www.breadmanrises.com
FB travel group: The Breadman Rises

Post Reply