Encrypt and Decrypt errors

Post Reply
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Encrypt and Decrypt errors

Post 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?
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
carlos vargas
Posts: 1421
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: Encrypt and Decrypt errors

Post 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
 
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: Encrypt and Decrypt errors

Post 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 )
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: Encrypt and Decrypt errors

Post by Silvio.Falconi »

I tried to Use your function but it seem not run ok

Image

Look the get top at right
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: Encrypt and Decrypt errors

Post by Silvio.Falconi »

Sorry My mistake run ok
I forget to set LOGIN_KEY
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
carlos vargas
Posts: 1421
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: Encrypt and Decrypt errors

Post by carlos vargas »

OK.
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
fraxzi
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines
Contact:

Re: Encrypt and Decrypt errors

Post by fraxzi »

Hi All,

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

:?:
Kind Regards,
Frances

Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
User avatar
fraxzi
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines
Contact:

Re: Encrypt and Decrypt errors

Post by fraxzi »

I got it...

Str2Hex() and Hex2Str() ...

:)
Kind Regards,
Frances

Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
User avatar
carlos vargas
Posts: 1421
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: Encrypt and Decrypt errors

Post by carlos vargas »

please include

Code: Select all

#include "hbcompat.ch"
 
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
fraxzi
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines
Contact:

Re: Encrypt and Decrypt errors

Post by fraxzi »

carlos vargas wrote:please include

Code: Select all

#include "hbcompat.ch"
 

Thanks Carlos!

:)
Kind Regards,
Frances

Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
Post Reply