![]() |
|
|
|
#1
|
|||
|
|||
|
Delphi + DCPCrypt 2 (RC6) vs RAD Studio + DCPCrypt 2 (RC6) = KABOOM!
Hi...
Just a question: I've coded an application with delphi, that generates files encrypted with RC6, just as a security measure so the user must generate file through the program and not by hand with notepad. Later on...i moved to RAD Studio XE and used exactly the same files (no modifications at all), to further develop the program to version 2. Well...hard to say, but RC6 fails. Files generated by version 1 (delphi 7) are unreadable from version 2 (rad studio xe). From what i see, difference is not so important...it happens very rarely... here it is an example: Plain String before encryption: ###BDB###R#G#Gx#V#RG#RGx#RV#GG#GV#GxVx#GxVy#RGG#RGV#RGxVx#RGxVy#R#G#Gx#V#RG#RGx#RV#GG#GV#GxVx#GxVy#RGG#RGV#RGxVx#RGxVy###EDB######BOB###3###EOB### Plain String after decryption: ###BDB#oŽVÌ'#$0090'NŒ™^Z'#$11'‹.M™“#RV#GG#GV#GxVx#GxVy#RGG#RGV#RGxVx#RGxVy#R#G#Gx#V#RG#RGx#RV#GG#GV#GxVx#GxVy#RGG#RGV#RGxVx#RGxVy###EDB######BOB###3###EOB### As you can see...something breaks in the middle...you can try with various other strings...and it happens the same...even multiple times if the string is long enough. One thought came to my mind: Delphi 7 is ASCII while RAD Studio XE is UNICODE. That causes many problems and a new version of DPCrypt 2 has been released to address UNICODE issues... I have even problems encrypting and decrypting with the same library on RAD Studio XE by itself...it encrypts but after decryption the result is the same of above. So the question is: a) is it normal that going unicode, i receive different results. If I try on delphi 7 everything is fine...on rad studio and between different versions of delphi the entire thing go mess. b) what can be the problem? dpcrypt 2, unicode, rad studio xe or other things? It's a month that I'm bashing my head on the pc without a solution...tried to change everything but this is the most close to unencrypted i got... Thanks in advance to everyone... (P.S. I can share the code if necessary, nothing secret) |
|
#2
|
||||
|
||||
|
UNICODE is the first thing that came to my mind too.
Git |
|
#3
|
|||
|
|||
|
What drives me absolutely MAD is that it is QUITE correct...but not ALL correct.
The difference between the before and after is minimal... ###BDB###R#G#Gx#V#RG#RGx#RV# ###BDB#oŽVÌ'#$0090'NŒ™^Z'#$11'‹.M™“#RV# only 16 digits...so 128 bits? It's so nonsense...it seems like one round fails and the others don't. I can't even think about a possible solutions...if the sha1 key was incorrect, the entire decryption should be incorrect but i find miself with partial correct decryption and partial incorrect decryption...and that's crazy... I looked everywhere, but everything is set to take AnsiString...so it is correct. Are there other entities that changed from Ansi to Unicode? |
|
#4
|
||||
|
||||
|
I've heard that the type 'Char' has been changed from 'AnsiChar' (8bit) to 'WideChar' (16bit) as well. Perhaps your RC6 algo uses this type.
__________________
Real programmers don't read manuals. Reliance on a reference is a hallmark of the novice and the coward. |
|
#5
|
|||
|
|||
|
there is no "Char" use, but there is a function called "FillChar" that may be causing problems. I don't know how to replace and Embarcadero tips don't work.
I'm currently reviewing for the 100th time all the code and found out that the Decrypt routine does not use FillChar, so it should be safe. The problems may arise in the Initialisation of the Key or in the Creation of the Cipher (Cipher:= TDCP_rc6.Create(nil); Cipher.InitStr(KeyStr,TDCP_sha1) so I'm investigating this way...UPDATE1: Cipher:= TDCP_rc6.Create(nil); does nothing else than filling KeyData (which is an array of DWord) with $FF and IV and CV (which are array of byte) again with $FF. So unless there is something else wrong, it shouldn't be the culprit... Last edited by TmC; 10-20-2011 at 08:53. |
|
#6
|
|||
|
|||
|
UPDATE2: I think i got a hold on the whole damn thing... The problem is the following(yet to disclose how to fix it though...):
a) if I load the encrypted text from a file into a string and decrypt that string, the whole damn thing breaks. b) if I load the encrypted text from a constant string hardcoded into rad studio xe, the whole damn thing breaks. c) if I load the encrypted text from a Memo.Text and execute RC6Decrypt(Memo1.Text), THE WHOLE DAMN THING WORKS AND DECRYPTS SUCCESFULLY. So...I am now trying to understand why loading it in a textbox makes it succeed while loading from a string it kills himself... Worse...if i load the encrypted text into a string, and then send it to Memo, the thing FAILS, if i copy from the encrypted file the binary data and paste it directly into memo, the thing WORKS... Does this make any sense? |
|
#7
|
|||
|
|||
|
TmC
attach your sample Delphi project here please the chances will raise once people will take a look over |
![]() |
| Thread Tools | |
| Display Modes | |
|
|