hb_crypt and hb_decrypt problem

Post Reply
User avatar
ricbarraes
Posts: 55
Joined: Tue Jun 30, 2015 2:26 am
Location: Brazil

hb_crypt and hb_decrypt problem

Post by ricbarraes »

Hey everybody!

I'm encrypting some data on my application with a random salt and I found out a problem like this:

Code: Select all | Expand

hb_crypt("@Selva123","LVLVDTWRQHVYCDTP")

hb_decrypt(hb_crypt("@Selva123","LVLVDTWRQHVYCDTP"),"LVLVDTWRQHVYCDTP")
 


it encrypts the data but it was not able to decrypt using the same key...

that's how I'm generating the key:

Code: Select all | Expand

FOR N=1 TO 16
      nChar:=HB_RandomInt( 65, 90 )      
      cSalt+=Chr(nChar)
   NEXT N


Does anybody know what is wrong?
Sds,
Ricardo Arraes
ricardo@vfatec.com.br
User avatar
anserkk
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India
Has thanked: 2 times

Re: hb_crypt and hb_decrypt problem

Post by anserkk »

I am getting the desired output as per your sample ie when I decrypt the result is @Selva123

Code: Select all | Expand

#Include "Fivewin.ch"
Function Main()

    ? hb_crypt("@Selva123","LVLVDTWRQHVYCDTP")

    ? hb_decrypt(hb_crypt("@Selva123","LVLVDTWRQHVYCDTP"),"LVLVDTWRQHVYCDTP")

Return NIL

If you are writing the encrypted value to some file and then later trying to decrypt the value then please try StrToHex() and HexToStr()
User avatar
ricbarraes
Posts: 55
Joined: Tue Jun 30, 2015 2:26 am
Location: Brazil

Re: hb_crypt and hb_decrypt problem

Post by ricbarraes »

anserkk wrote:I am getting the desired output as per your sample ie when I decrypt the result is @Selva123

Code: Select all | Expand

#Include "Fivewin.ch"
Function Main()

    ? hb_crypt("@Selva123","LVLVDTWRQHVYCDTP")

    ? hb_decrypt(hb_crypt("@Selva123","LVLVDTWRQHVYCDTP"),"LVLVDTWRQHVYCDTP")

Return NIL

If you are writing the encrypted value to some file and then later trying to decrypt the value then please try StrToHex() and HexToStr()
Thank you my friend!

In fact I’m saving it in a MariaDB table as a LONGBLOB column. Do I need to use strtohex and hextostr to store it properly? And which one do I have to use to save and to retrieve the content?


Enviado do meu iPhone usando Tapatalk
Sds,
Ricardo Arraes
ricardo@vfatec.com.br
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: hb_crypt and hb_decrypt problem

Post by nageswaragunupudi »

In case you are using built-in FWH MariaDB/MySql library, you need not worry about it. The library automatically takes care of the
conversions.

Example Usage:

Code: Select all | Expand


oRs:photo := MEMOREAD( "photo.jpg" )
oRs:Save()
 


Without opening the table as rowset:

Code: Select all | Expand


oCn:Insert( cTable, "NAME,PHOTO", { "Albert", MEMOREAD( "albert.jpg" ) } )
// OR
oCn:Update( cTable, "PHOTO", { MEMOREAD( "newphoto.jpg" ) }, "ID=230" )
 


If you use any other library or want to write your own SQL statements to insert or update a table use
"0x" + STRTOHEX( MEMOREAD( cFile ) ), without enclosing in quotes.

You can also use FW_ValToSQL( cBinaryText, .t., "MYSQL" )
Note: The conversion is different for different databases. FW_ValToSQL takes care of this.
Regards

G. N. Rao.
Hyderabad, India
Post Reply