FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Encryption error! (SOLVED)
Posts: 100
Joined: Fri Dec 12, 2008 04:39 PM
Encryption error! (SOLVED)
Posted: Mon Jan 23, 2012 02:13 PM
Good day!

Intermittently I get an error in the encryption / decryption of a given string here on my system.

Here the piece of code:

Code (fw): Select all Collapse
cChave: = 'TI040505' / / fictional

retorno_cbx: = 'UR010801752' / / actual
seriec: = 'UR010801752' / / actual

cChave: = ALLTRIM (cChave)

replace serie with space(len(serie))
replace seriec with space(len(seriec))
dbcommit ()

replace serie with ALLTRIM(retorno_cbx)
replace seriec with Encrypt(ALLTRIM(retorno_cbx), cChave)

retorno_cbx: = Decrypt(ALLTRIM(seriec), cChave))


Decryption is done when the string is returned a string that is not the same as it was recorded.

Is there any solution for this?


Thank you!
Contagem/Brazil

FWH/xharbour 15.12/PELLES C, MED, DBF
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: Encryption error!
Posted: Fri Jan 27, 2012 08:40 AM

Have you tried these other functions?

HB_CRYPT( cBufferIn, cKey ) )

HB_DECRYPT( cBufferIn, cKey ) )

maybe you can fix...

Marco Boschi
info@marcoboschi.it
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Encryption error!
Posted: Fri Jan 27, 2012 10:17 AM

Try this and check if it works fine for you:

MsgInfo( Decrypt( Encrypt( "Hello world", "password" ), "password" ) )

Here it is working fine and shows "Hello world"

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 100
Joined: Fri Dec 12, 2008 04:39 PM
Re: Encryption error!
Posted: Fri Jan 27, 2012 11:18 AM

Good day!

Marco, by using the HB_Crypt the error is more constant!

I tested using the example of Antonio and worked with my data, the routine will check again to try to locate the problem!

Post here the result.

Thank you!

Contagem/Brazil

FWH/xharbour 15.12/PELLES C, MED, DBF
Posts: 100
Joined: Fri Dec 12, 2008 04:39 PM
Re: Encryption error!
Posted: Fri Jan 27, 2012 12:00 PM
Please test the code below:

Code (fw): Select all Collapse
cChave := 'TIAO'

cTeste1 := 'UR010801733' // FIELD OF THE FOURTH The DBF THAT WITH ENCRYPTION SIZE 40 CHARACTER

MSGINFO(cTeste1)

cTeste2 := Encrypt(cTeste1, cChave)

msginfo(cTeste2)

cteste3 := Decrypt(alltrim(cTeste2),cChave)

msginfo(cteste3)


Test done using FWH / xHarbour 11.12

Thank you!
Contagem/Brazil

FWH/xharbour 15.12/PELLES C, MED, DBF
Posts: 344
Joined: Tue Oct 11, 2005 11:33 AM
Re: Encryption error!
Posted: Fri Jan 27, 2012 08:00 PM
Olá Tião,

Teu erro está nesta linha:

cteste3 := Decrypt(alltrim(cTeste2),cChave)

tem que ser assim:

cteste3 := alltrim(hb_Decrypt(cTeste2,cChave)) // olha o alltrim()

segue exemplo compilado em harbour puro:

Code (fw): Select all Collapse
function MAIN

cChave := 'TIAO'

cTeste1 := 'UR010801733' // FIELD OF THE FOURTH The DBF THAT WITH ENCRYPTION SIZE 40 CHARACTER

? cTeste1

cTeste2 := hb_crypt(cTeste1, cChave)

? cTeste2

cteste3 := alltrim(hb_Decrypt(cTeste2,cChave))

? cTeste3

return NIL


Veja se isto funciona aí pra você,

Abraços,

Rossine.
Obrigado, Regards, Saludos



Rossine.



Harbour and Harbour++
Posts: 100
Joined: Fri Dec 12, 2008 04:39 PM
Re: Encryption error!
Posted: Fri Jan 27, 2012 08:43 PM
Rossine wrote:Olá Tião,

Teu erro está nesta linha:

cteste3 := Decrypt(alltrim(cTeste2),cChave)

tem que ser assim:

cteste3 := alltrim(hb_Decrypt(cTeste2,cChave)) // olha o alltrim()

segue exemplo compilado em harbour puro:

Code (fw): Select all Collapse
function MAIN

cChave := 'TIAO'

cTeste1 := 'UR010801733' // FIELD OF THE FOURTH The DBF THAT WITH ENCRYPTION SIZE 40 CHARACTER

? cTeste1

cTeste2 := hb_crypt(cTeste1, cChave)

? cTeste2

cteste3 := alltrim(hb_Decrypt(cTeste2,cChave))

? cTeste3

return NIL


Veja se isto funciona aí pra você,

Abraços,

Rossine.


Oi rossini, ja tentei usar a função HB_Crypt, mas ela tambem apresenta problema com determinadas strings, como o Fivewin possui a função própria e é mais facil pedir o auxílio ao Linhares preferi ver se consigo solução atraves da CRYPT/DECRYPT.

Mesmo assim obrigado!
Contagem/Brazil

FWH/xharbour 15.12/PELLES C, MED, DBF
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: Encryption error!
Posted: Fri Jan 27, 2012 09:41 PM
Hello


you can not use Alltrim in encrypted string, because some character converted maybe there are useful, in your case the first char is a CHR(10) and you are deleting this with alltrim function

try to understand my point

cteste3 := Decrypt(chr(10)+alltrim( cTeste2 ),cChave)

i personally do it...
convert the encrypted text to base64 encode using hb_base64encode/ hb_base64decode, using base64 i can save to table, dbf, ini file without problem

it's a test

#include "fivewin.ch"


Code (fw): Select all Collapse
function main()
local cChave, cTeste1, cTeste2
cChave := 'TIAO'

cTeste1 := 'UR010801733' // FIELD OF THE FOURTH The DBF THAT WITH ENCRYPTION SIZE 40 CHARACTER

MSGINFO(cTeste1)

cTeste2 := hb_Base64Encode( Encrypt(cTeste1, cChave) )

Msginfo( cTeste2 )

cteste3 := Decrypt( hb_Base64Decode( cTeste2 ),cChave)

msginfo(cteste3)

return nil
Posts: 100
Joined: Fri Dec 12, 2008 04:39 PM
Re: Encryption error!
Posted: Mon Jan 30, 2012 01:17 PM
Daniel Garcia-Gil wrote:Hello


you can not use Alltrim in encrypted string, because some character converted maybe there are useful, in your case the first char is a CHR(10) and you are deleting this with alltrim function

try to understand my point

cteste3 := Decrypt(chr(10)+alltrim( cTeste2 ),cChave)

i personally do it...
convert the encrypted text to base64 encode using hb_base64encode/ hb_base64decode, using base64 i can save to table, dbf, ini file without problem

it's a test

#include "fivewin.ch"


Code (fw): Select all Collapse
function main()
local cChave, cTeste1, cTeste2
cChave := 'TIAO'

cTeste1 := 'UR010801733' // FIELD OF THE FOURTH The DBF THAT WITH ENCRYPTION SIZE 40 CHARACTER

MSGINFO(cTeste1)

cTeste2 := hb_Base64Encode( Encrypt(cTeste1, cChave) )

Msginfo( cTeste2 )

cteste3 := Decrypt( hb_Base64Decode( cTeste2 ),cChave)

msginfo(cteste3)

return nil




Hello Daniel,

Thanks for the reply!

Can you tell me what is the lib that contains the function hb_base64decode and where do I get?.

I use xHarbour!

Great week!
Contagem/Brazil

FWH/xharbour 15.12/PELLES C, MED, DBF
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: Encryption error!
Posted: Mon Jan 30, 2012 02:21 PM

Hello

sorry, this function is not added in xHarbour, the code exist, but is not added to lib

i'll test to try added it

Posts: 100
Joined: Fri Dec 12, 2008 04:39 PM
Re: Encryption error!
Posted: Mon Jan 30, 2012 02:29 PM
Daniel Garcia-Gil wrote:Hello

sorry, this function is not added in xHarbour, the code exist, but is not added to lib

i'll test to try added it



Thank you!
Contagem/Brazil

FWH/xharbour 15.12/PELLES C, MED, DBF
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: Encryption error!
Posted: Mon Jan 30, 2012 02:35 PM
Hello

the current base64 code from xharbour not work properly, i modified the code and rebuilt the lib affected

please download the new lib http://www.sitasoft.net/fivewin/files/tip.zip
Posts: 100
Joined: Fri Dec 12, 2008 04:39 PM
Re: Encryption error!
Posted: Mon Jan 30, 2012 10:58 PM
"e="Daniel Garcia-Gil"]Hello

the current base64 code from xharbour not work properly, i modified the code and rebuilt the lib affected

please download the new lib http://www.sitasoft.net/fivewin/files/tip.zip




Thank you Daniel!

Doing some testing here with the new tip.lib, I noticed a strange behavior apparently function hb_base64encode/hb_base64decode.

Please test the following code:


Code (fw): Select all Collapse
for x := 1 to 10

    cChave := 'TIAO'

    cTeste1 := 'EMULADOR' // 'UR010801733' // CAMPO DO DBF QUE QUARTA A CRIPTOGRAFIA COM TAMANHO DE 40 CARACTERES

    MSGINFO(cTeste1)

    cTeste2 := hb_Base64Encode(Encrypt(cTeste1, cChave))

    msginfo(cTeste2)

    cteste3 := Decrypt(hb_Base64Decode(cTeste2),cChave)

    msginfo(cteste3)

next


In some steps the return of function is different, you see!

Any idea what may be motivating the error?"
Contagem/Brazil

FWH/xharbour 15.12/PELLES C, MED, DBF
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: Encryption error!
Posted: Mon Jan 30, 2012 11:18 PM
Posts: 100
Joined: Fri Dec 12, 2008 04:39 PM
Re: Encryption error!
Posted: Tue Jan 31, 2012 12:57 AM
Daniel Garcia-Gil wrote:Hello

download the new lib http://www.sitasoft.net/fivewin/files/tip.zip



Thank you Daniel!

Perfect!

I'll try more!

Any problems you know!
Contagem/Brazil

FWH/xharbour 15.12/PELLES C, MED, DBF

Continue the discussion