Encryption error! (SOLVED)

Post Reply
tiaofw
Posts: 97
Joined: Fri Dec 12, 2008 4:39 pm
Location: Brasil
Contact:

Encryption error! (SOLVED)

Post by tiaofw »

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


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
User avatar
MarcoBoschi
Posts: 925
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy
Contact:

Re: Encryption error!

Post by MarcoBoschi »

Have you tried these other functions?

HB_CRYPT( cBufferIn, cKey ) )

HB_DECRYPT( cBufferIn, cKey ) )

maybe you can fix...
Marco Boschi
info@marcoboschi.it
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Encryption error!

Post by Antonio Linares »

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

Re: Encryption error!

Post by tiaofw »

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

Re: Encryption error!

Post by tiaofw »

Please test the code below:

Code: Select all


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

Re: Encryption error!

Post by Rossine »

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


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.

xHarbour comercial (xAcc) -> Testando harbour + bcc / msvc
fwh 9.05
Windows XP SP2
tiaofw
Posts: 97
Joined: Fri Dec 12, 2008 4:39 pm
Location: Brasil
Contact:

Re: Encryption error!

Post by tiaofw »

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


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
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

Re: Encryption error!

Post by Daniel Garcia-Gil »

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

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
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
tiaofw
Posts: 97
Joined: Fri Dec 12, 2008 4:39 pm
Location: Brasil
Contact:

Re: Encryption error!

Post by tiaofw »

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

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
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

Re: Encryption error!

Post by Daniel Garcia-Gil »

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
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
tiaofw
Posts: 97
Joined: Fri Dec 12, 2008 4:39 pm
Location: Brasil
Contact:

Re: Encryption error!

Post by tiaofw »

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
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

Re: Encryption error!

Post by 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
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
tiaofw
Posts: 97
Joined: Fri Dec 12, 2008 4:39 pm
Location: Brasil
Contact:

Re: Encryption error!

Post by tiaofw »

"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


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
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

Re: Encryption error!

Post by Daniel Garcia-Gil »

our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
tiaofw
Posts: 97
Joined: Fri Dec 12, 2008 4:39 pm
Location: Brasil
Contact:

Re: Encryption error!

Post by tiaofw »

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
Post Reply