Page 1 of 1

Encrypt and Decrypt errors

Posted: Tue Sep 11, 2018 8:15 am
by Silvio.Falconi
On a ftp procedure I use this configuration to upload and download a file from fwh

Code: Select all

   Local cFtp     :=( pad(GetPvProfString("Config","Ftp" ,""   ,::cIniFtp ) , 60 ," " ) )
   Local cFtpDir  :=( pad(GetPvProfString("Config","FtpDir" ,"",::cIniFtp ) , 60 ," " ) )
   Local cUser    :=( pad(GetPvProfString("Config","User" ,""  ,::cIniFtp ) , 60 ," " ) )
   Local cPws     :=( pad(GetPvProfString("Config","Password" ,""  ,::cIniFtp ) , 60 ," " ) )
   Local cUpdFile :=( pad(GetPvProfString("Config","Filename" ,""  ,::cIniFtp ) , 60 ," " ) )
   Local cLocalDir:=( pad(GetPvProfString("Config","Cartella" ,""  ,::cIniFtp ) , 60 ," " ) )
 
I wish use Encrypt and Decrypt functions

WritePProString("Config","Ftp",Encrypt(cFtp),::cIniFtp)
or
Local cFtp :=Decrypt( pad(GetPvProfString("Config","Ftp" ,"" ,::cIniFtp ) , 60 ," " ) )

When I encrypt fwh run ok and the infodata are save on ini file

but I use decrypt and I wish load the info data I saved it not return the data clear


Image



If I insert a IP for sample 168.200.1.1 instead ftp.xxxx.it

it make error

Any solution please?

Re: Encrypt and Decrypt errors

Posted: Tue Sep 11, 2018 9:32 pm
by carlos vargas
Silvio, the Encrypt function may be generating non-printable characters which generate this type of problems, the ideal is to complement it with the functions that work with hexadecimal.

Code: Select all

WritePProString("Config","Ftp",Str2HexCrypt(cFtp),::cIniFtp)
or
Local cFtp :=HexCrypt2Str( pad(GetPvProfString("Config","Ftp" ,"" ,::cIniFtp ) , 60 ," " ) )
 

Code: Select all

#define LOGIN_KEY "MySeed2018"

FUNCTION Str2HexCrypt( cString, nSize, cSeed )
   LOCAL cHex := ""

   DEFAULT nSize := Len( cString ), cSeed := LOGIN_KEY

   IF !Empty( cString )
      IF nSize > 0
         cHex := HB_StrToHex( HB_Crypt( PadR( cString, nSize ), cSeed ) )
      ELSE
         cHex := HB_StrToHex( HB_Crypt( cString, cSeed ) )
      ENDIF
   ENDIF

RETURN cHex

/*-------------------------------------------------------------------------------------------------*/

FUNCTION HexCrypt2Str( cStringHex, cSeed )
   LOCAL cStr := ""

   DEFAULT cSeed := LOGIN_KEY

   IF !Empty( cStringHex )
      cStr := HB_Decrypt( HB_HexToStr( cStringHex ), cSeed )
   ENDIF

RETURN cStr
 

Re: Encrypt and Decrypt errors

Posted: Wed Sep 12, 2018 10:21 am
by Silvio.Falconi
thanks
I saw the functions
you have correct also the encrypt function or there is not problem for the encrypt ?
do you have found aes cript functions )

Re: Encrypt and Decrypt errors

Posted: Wed Sep 12, 2018 10:30 am
by Silvio.Falconi
I tried to Use your function but it seem not run ok

Image

Look the get top at right

Re: Encrypt and Decrypt errors

Posted: Wed Sep 12, 2018 10:36 am
by Silvio.Falconi
Sorry My mistake run ok
I forget to set LOGIN_KEY

Re: Encrypt and Decrypt errors

Posted: Wed Sep 12, 2018 5:26 pm
by carlos vargas
OK.

Re: Encrypt and Decrypt errors

Posted: Wed Sep 19, 2018 2:39 am
by fraxzi
Hi All,

how to use HB_StrToHex()/HB_HexToStr() in xHarbour ... Any equivalent?

:?:

Re: Encrypt and Decrypt errors

Posted: Wed Sep 19, 2018 2:57 am
by fraxzi
I got it...

Str2Hex() and Hex2Str() ...

:)

Re: Encrypt and Decrypt errors

Posted: Wed Sep 19, 2018 5:22 pm
by carlos vargas
please include

Code: Select all

#include "hbcompat.ch"
 

Re: Encrypt and Decrypt errors

Posted: Thu Sep 20, 2018 7:03 am
by fraxzi
carlos vargas wrote:please include

Code: Select all

#include "hbcompat.ch"
 

Thanks Carlos!

:)