How to make encrypt()/decrypt() produce same result in 16/32

Post Reply
hua
Posts: 861
Joined: Fri Oct 28, 2005 2:27 am

How to make encrypt()/decrypt() produce same result in 16/32

Post by hua »

How to enable encrypt()/decrypt() to produce the same result in 16 and 32 bits version? So far I noticed a 16-bit decrypt() can't correctly decrypt a string encrypted by a 32-bit encrypt().

Any help is much appreciated as it's quite urgent.

TIA.
Last edited by hua on Thu Mar 22, 2007 8:55 am, edited 1 time in total.
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Hua,

We are going to review this issue as soon as possible.

We are actually at Holland providing a FWPPC seminar but today we will look for some free time to review it
regards, saludos

Antonio Linares
www.fivetechsoft.com
hua
Posts: 861
Joined: Fri Oct 28, 2005 2:27 am

Post by hua »

Thanks Antonio. Appreciate it :)
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Hua,

We have tested it in both 16 and 32 bits and the results are the same.

Could you please provide a sample where the encrypted result is different ? thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
hua
Posts: 861
Joined: Fri Oct 28, 2005 2:27 am

Post by hua »

Sorry for the late reply Antonio. Got to finish other stuffs that were due first. A brief description about the following samples. There would be 2 exe involved. The 32-bit exe would be calling the 16-bit exe.

This is the code for the 32-bit exe. (FWH2.8+xHarbour 0.99.61)

Code: Select all

#include "FiveWin.ch"

function Main()

   local oDlg, oIco, cId := "SUPERVISOR"

   DEFINE ICON oIco FILE "..\icons\fivewin.ico"

   DEFINE DIALOG oDlg TITLE "I am a DialogBox" COLOR "W+/B" ;
      ICON oIco


   @ 3, 5 BUTTON "Run module" SIZE 40, 12 ;
      ACTION winexec("exe16.exe "+encrypt(trim(cId))  )


   ACTIVATE DIALOG oDlg CENTERED

return nil
And this is the code for the 16-bit exe. (FW2.3+Clipper 5.2)

Code: Select all

#include "fivewin.ch"

function main16(cID)

  default cId := ""
  msginfo(decrypt(trim(cID)))

return nil
The resulting string is not SUPERVISOR as expected.
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Hua,

Thats risky: the encrypted result may contain embedded zeroes that the application initialization may not properly parse.

Better write the encrypted text to a file and read that file from the 16 bits EXE
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Hua,

>Better write the encrypted text to a file and read that file from the 16 bits EXE

If you do this, don't forget to securely erase the file after reading it. I don't mean to just delete it, but to write dummy data to it multiple times before deleting it.

James
hua
Posts: 861
Joined: Fri Oct 28, 2005 2:27 am

Post by hua »

Antonio, James, thanks for the feedback and input. It never occur to me that passing encrypted string as I was doing could be problematic as the string length stays the same in exe32 and exe16.
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Hua,

I don't know if this will work, but you could try:

@ 3, 5 BUTTON "Run module" SIZE 40, 12 ;
ACTION winexec([exe16.exe ]+["]+encrypt(trim(cId))+["] )

Enclosing the passed parameter in quotes may fix any problems with spaces in cID.

James
hua
Posts: 861
Joined: Fri Oct 28, 2005 2:27 am

Post by hua »

Thanks for the idea James. I just find it odd that if both the above samples are compiled in 16-bit I do get the expected string i.e. SUPERVISOR
User avatar
AlexSchaft
Posts: 172
Joined: Fri Oct 07, 2005 1:29 pm
Location: Edenvale, Gauteng, South Africa

Passing encrypted strings

Post by AlexSchaft »

Hi,

Another trick I use where high (>127) ascii and low(<32) can be tricky is to mime encode the strings

Code: Select all


   @ 3, 5 BUTTON "Run module" SIZE 40, 12 ;
      ACTION winexec("exe16.exe "+cmimeenc(encrypt(trim(cId)))  ) 

and

Code: Select all

msginfo(trim(decrypt(cmimedec(cId))))
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Hua,

>Thanks for the idea James. I just find it odd that if both the above samples are compiled in 16-bit I do get the expected string i.e. SUPERVISOR.

Granted that does seem odd. Are you using the same versions of FW and FWH? Perhaps there was a change in the versions that is causing the problem rather than 16bit vs 32bit.

James
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

James,

There have not been changes in functions Encrypt() and Decrypt() source code. Its easy to check that their results are compatible, so Hua problem has to be something else. Maybe something related to calling 16 bits from 32 bits.
regards, saludos

Antonio Linares
www.fivetechsoft.com
hua
Posts: 861
Joined: Fri Oct 28, 2005 2:27 am

Post by hua »

James wrote: @ 3, 5 BUTTON "Run module" SIZE 40, 12 ;
ACTION winexec([exe16.exe ]+["]+encrypt(trim(cId))+["] )
Unfortunately, the above didn't work James.
James wrote: Granted that does seem odd. Are you using the same versions of FW and FWH? Perhaps there was a change in the versions that is causing the problem rather than 16bit vs 32bit.
No. I'm using FW2.3 and FWH2.8 respectively. I'm holding on to a time-tested principle, "if it ain't broken, don't fix it". :D Hence my reluctance to touch anything that's working fine so I left my 16-bit programs with FW16. I doubt there was a change, if there was, a lot more people would've been affected.
AlexSchaft wrote: Another trick I use where high (>127) ascii and low(<32) can be tricky is to mime encode the strings
Hey, that's a neat trick there Alex. I'll keep it in mind. I know it'd have never crossed my mind.
Post Reply