Encryption error! (SOLVED)

Encryption error! (SOLVED)

Postby tiaofw » Mon Jan 23, 2012 2: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: Select all  Expand view


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!
Last edited by tiaofw on Tue Jan 31, 2012 6:42 pm, edited 1 time in total.
Contagem/Brazil
FWH/xharbour 15.12/PELLES C, MED, DBF
tiaofw
 
Posts: 99
Joined: Fri Dec 12, 2008 4:39 pm
Location: Brasil

Re: Encryption error!

Postby MarcoBoschi » Fri Jan 27, 2012 8:40 am

Have you tried these other functions?

HB_CRYPT( cBufferIn, cKey ) )

HB_DECRYPT( cBufferIn, cKey ) )

maybe you can fix...
User avatar
MarcoBoschi
 
Posts: 1015
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Encryption error!

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Encryption error!

Postby tiaofw » 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
tiaofw
 
Posts: 99
Joined: Fri Dec 12, 2008 4:39 pm
Location: Brasil

Re: Encryption error!

Postby tiaofw » Fri Jan 27, 2012 12:00 pm

Please test the code below:

Code: Select all  Expand view


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
tiaofw
 
Posts: 99
Joined: Fri Dec 12, 2008 4:39 pm
Location: Brasil

Re: Encryption error!

Postby Rossine » Fri Jan 27, 2012 8: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: Select all  Expand view


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++
Rossine
 
Posts: 344
Joined: Tue Oct 11, 2005 11:33 am

Re: Encryption error!

Postby tiaofw » Fri Jan 27, 2012 8: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: Select all  Expand view


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
tiaofw
 
Posts: 99
Joined: Fri Dec 12, 2008 4:39 pm
Location: Brasil

Re: Encryption error!

Postby Daniel Garcia-Gil » Fri Jan 27, 2012 9: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: Select all  Expand view
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
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Encryption error!

Postby tiaofw » Mon Jan 30, 2012 1: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: Select all  Expand view
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
tiaofw
 
Posts: 99
Joined: Fri Dec 12, 2008 4:39 pm
Location: Brasil

Re: Encryption error!

Postby Daniel Garcia-Gil » Mon Jan 30, 2012 2: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
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Encryption error!

Postby tiaofw » Mon Jan 30, 2012 2: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
tiaofw
 
Posts: 99
Joined: Fri Dec 12, 2008 4:39 pm
Location: Brasil

Re: Encryption error!

Postby Daniel Garcia-Gil » Mon Jan 30, 2012 2: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
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Encryption error!

Postby tiaofw » 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: Select all  Expand view


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
tiaofw
 
Posts: 99
Joined: Fri Dec 12, 2008 4:39 pm
Location: Brasil

Re: Encryption error!

Postby Daniel Garcia-Gil » Mon Jan 30, 2012 11:18 pm

User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Encryption error!

Postby tiaofw » 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
tiaofw
 
Posts: 99
Joined: Fri Dec 12, 2008 4:39 pm
Location: Brasil


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot], nageswaragunupudi and 93 guests