Encrypt/Decrypt with AES to dbf table
-
- Posts: 4
- Joined: Wed Dec 11, 2019 7:18 am
Encrypt/Decrypt with AES to dbf table
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"
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 1015 times
Re: Encrypt/Decrypt with AES to dbf table
Hi, encrypted string need more space than source string.
Have you enought field size ?
Have you enought field size ?
Re: Encrypt/Decrypt with AES to dbf table
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.
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.
Re: Encrypt/Decrypt with AES to dbf table
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
Dian
Avatar Systems
-
- Posts: 4
- Joined: Wed Dec 11, 2019 7:18 am
Re: Encrypt/Decrypt with AES to dbf table
Thank you very much, that resolved my issue!
Re: Encrypt/Decrypt with AES to dbf table
Roger's old, but not THAT oldDian wrote:first started using express back in 200 or so.
Dian
Avatar Systems
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 traveling right now...
http://www.breadmanrises.com
FB travel group: The Breadman Rises
Retired and traveling around the country to music festivals in my RV.
OOPS.. Corona Virus, so NOT traveling right now...
http://www.breadmanrises.com
FB travel group: The Breadman Rises
Re: Encrypt/Decrypt with AES to dbf table
Have you forgotten that I was the guy who brought Clipper development out of the stone age?Roger's old, but not THAT old
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.
The eXpress train is coming - and it has more cars.
Re: Encrypt/Decrypt with AES to dbf table
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..rdonnay wrote:Have you forgotten that I was the guy who brought Clipper development out of the stone age?Roger's old, but not THAT old
(ok, your turn.. )
Brian Wolfsohn
Retired and traveling around the country to music festivals in my RV.
OOPS.. Corona Virus, so NOT traveling right now...
http://www.breadmanrises.com
FB travel group: The Breadman Rises
Retired and traveling around the country to music festivals in my RV.
OOPS.. Corona Virus, so NOT traveling right now...
http://www.breadmanrises.com
FB travel group: The Breadman Rises
Re: Encrypt/Decrypt with AES to dbf table
Ah yes.you walked into the dBase lounge
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"
The eXpress train is coming - and it has more cars.
Re: Encrypt/Decrypt with AES to dbf table
And then you said:rdonnay wrote:Ah yes.you walked into the dBase lounge
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"
"Try compiling... The first one's free"
Brian Wolfsohn
Retired and traveling around the country to music festivals in my RV.
OOPS.. Corona Virus, so NOT traveling right now...
http://www.breadmanrises.com
FB travel group: The Breadman Rises
Retired and traveling around the country to music festivals in my RV.
OOPS.. Corona Virus, so NOT traveling right now...
http://www.breadmanrises.com
FB travel group: The Breadman Rises