hb_crypt and hb_decrypt problem

hb_crypt and hb_decrypt problem

Postby ricbarraes » Wed Aug 11, 2021 1:12 am

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 view
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 view
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
ricbarraes
 
Posts: 55
Joined: Tue Jun 30, 2015 2:26 am
Location: Brazil

Re: hb_crypt and hb_decrypt problem

Postby anserkk » Wed Aug 11, 2021 4:18 am

I am getting the desired output as per your sample ie when I decrypt the result is @Selva123
Code: Select all  Expand view
#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
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: hb_crypt and hb_decrypt problem

Postby ricbarraes » Wed Aug 11, 2021 12:35 pm

anserkk wrote:I am getting the desired output as per your sample ie when I decrypt the result is @Selva123
Code: Select all  Expand view
#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
ricbarraes
 
Posts: 55
Joined: Tue Jun 30, 2015 2:26 am
Location: Brazil

Re: hb_crypt and hb_decrypt problem

Postby nageswaragunupudi » Thu Aug 12, 2021 1:42 am

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 view

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


Without opening the table as rowset:
Code: Select all  Expand view

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
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 47 guests