Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
4
Erster Beitrag:
vor 8 Jahren, 1 Monat
Letzter Beitrag:
vor 8 Jahren
Beteiligte Autoren:
issah, Fabrice Harari.pcs.crosspost, Jimbo, Robin Lane.pcs.crosspost

Problem with "Simple" Encryption

Startbeitrag von Robin Lane.pcs.crosspost am 23.08.2009 15:18

Background:
We are looking for a simple way to protect our data form prying eyes. We do not need a complex encryption algorithm, this "protection" is simply
to dissuade people from modifying a simple set-up file which is to be downloaded from the web, and used in a C/VB6 application on a remote users PC.
The data exists in a server-side WinDev application, and will be read by a variety of other (non-Windev) applications after download.

Initially (for simplicity) we looked at WinDev's inbuilt fCrypt, which easily encrypted the file. All looked good, but then our problems began...
How to decrypt the file outwith WinDev.

As per the above, this file is to be read in a non-WinDev application. There seemed to be no method of synchronising the decrypt routine with the WinDev password.
All decryption routines outwith WinDev seems to need not only a password but also additional data such as an "IV Key" which WinDev does not.

To cut a long story short, remembering that we do not need a particularly strong cypher, we generated the following code to do it ourselves.



I have included my code below:

=========================================================================================================

sDataIn, sDataOut, sPassword are strings
x is int


sDataIn = "The wind was a torrent of darkness upon the gusty trees,
The moon was a ghostly galleon tossed upon cloudy seas,
The road was a ribbon of moonlight looping the purple moor,
And the highwayman came riding--
Riding--riding--
The highwayman came riding, up to the old inn door.

He'd a French cocked hat on his forehead, and a bunch of lace at his chin;
He'd a coat of the claret velvet, and breeches of fine doe-skin.
They fitted with never a wrinkle; his boots were up to his thigh!
And he rode with a jeweled twinkle--
His rapier hilt a-twinkle--
His pistol butts a-twinkle, under the jeweled sky."

sPassword = "WINDEV"

x = 0
FOR i = 1 TO Length(sDataIn)
sDataOut += Charact(BinaryXOR(Asc(Middle(sDataIn,i,1)),Asc(Middle(sPassword,x+1,1))))
x = (x + 1) modulo Length(sPassword)
END


//a trace of sDataout shows:
"!+d2?9-n3$%w(n0*$%, 0e91i*%7=9,=7e#'& d1>2i)16".i:6 3$enIO?,n)*99i9%6v6i),*%#%7d"7;%+++v#&=7 2w++v4%!1!/w:+%6zwDD-3w;!%!v (=d$v% ,&*8w&(d(98'"-">#i"+*&>')d1>2i>17&;,n)*9%enIO9-n0-3w!'#-!60#%+v4(#!e$>-'*"{ziCN?3 #h{% *-+1zdnIO?,n,,1?>/=(79i-%(3w;' ,80en15v#&n0-3w&" e?9'n *9%gnIO[]+c!v6i6 84!n'*5>:n"*$2!+%!zw( e7w+;*&>w&(d)74,n%1v? =d&>>'udH\,i e7w*!%1v8/n0-3w*"%73#i8!) 2=bd$83i,6 34!+7e91i(-+3w-!!h%< je[]&!'0-v9,8!7v6i96,8>:n&*9#:n3 $2i;4e"8i&-6v#!'#-wwDD+2w!+d793,n3,"?i/d/3 ,"!!v#>'*.:2dcdH\ =d77' +6e>>%:d${#>'*.:2dcdH\ =d5?$=!(e4"=:7e7z=9-+=;,bd083,2i$!23;,*d6=.g"


=========================================================================================================


Our encrypted data can be opened via Notepad but not by MS Word, which asks for "File Conversion Process"
The above line is purely for information / a pointer to the potential problem...

In reality we are tyring to open the file within a C/VB6 application. Opening and reading the plain text tile within our C/VB6 application is easy, But when
we try to open the encrypted file we receive an immediate "Input past end of file error"

The million dollar question is why???

Maybe this is because the BinaryXOR in the code is producing control characters which a standard file input class (and MS Word) does not like.

We have found that if we open the encrypted file for Binary input we can read the file. Our problem then is that there seems to be a size
limit on the file we can open...

Has anyone got some ideas that will help us??? We would be extremely grateful as we have been pulling ouor hair out with this for over a week.


Message forwarded from pcsoft.us.windev

Antworten:


Hi,

- the 'input past end error' comes up because your file has no EOF character and - of course - does not end at a 256 byte sector boundary, which means that a VB program will simply read a chunk more than it should.

Solution: encrypt your string using the option 'encodePCS' and write the result line by line to disk; reading line by line will prevent 'input past end'.

Regards,
Guenter



von Jimbo - am 23.08.2009 15:42

Re: Problem with "Simple" Encryption

Hi Robin...


> In reality we are tyring to open the file within a C/VB6 application. Opening and reading the plain text tile within our C/VB6 application is easy, But when
> we try to open the encrypted file we receive an immediate "Input past end of file error"

The message says that your file contains an EOF char which your text
reading routine doesn't like...

What you can do after encrypting your file is use a function like
URLEncode which will transform all control char in %xx (with xx being
the asc code). I'm sure you have the URLdecode function available in VB
too (or you can code it by hand, it's not difficult)

That should solve your file reading problem...

-OR-
you can create a small windev utility in charge of decrypting the files
and giving them decrypted to your external programs (as a .net asembly,
by example)

Best regards

--
Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

More information on http://www.fabriceharari.com



>
> The million dollar question is why???
>
> Maybe this is because the BinaryXOR in the code is producing control characters which a standard file input class (and MS Word) does not like.
>
> We have found that if we open the encrypted file for Binary input we can read the file. Our problem then is that there seems to be a size
> limit on the file we can open...
>
> Has anyone got some ideas that will help us??? We would be extremely grateful as we have been pulling ouor hair out with this for over a week.
>
>
Message forwarded from pcsoft.us.windev

von Fabrice Harari.pcs.crosspost - am 24.08.2009 12:11
I do something similar, but I use the zip functions with password protection. Even better than encryption, with smaller files also. You can open and extract the files with any zip archive reader as long as you know the password.

Use zip functions from an OCX on the VBS side to open and read the files.

regards

issah

von issah - am 24.08.2009 18:50
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.