Solved

Rijndael 128 bit Encryption with Delphi and PHP - 2

Posted on 2011-03-14
10
1,338 Views
Last Modified: 2013-11-19
Hi,
 
       Continue issue from: http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_26402183.html 

       I have same problem as JealousyPrince., I try to compile & test code provide by Slick812  but it does not working on Delphi 2010.  

       Source attached both Php & Delphi project.  Expert please help...

PhpAndD2010Encrypt.zip
0
Comment
Question by:charin1904
  • 5
  • 4
10 Comments
 
LVL 24

Assisted Solution

by:jimyX
jimyX earned 250 total points
ID: 35134809
I have updated the Delphi code. Please check and confirm:

DelphiCode-updated.zip
0
 

Author Comment

by:charin1904
ID: 35135613
@jimyX, Thank you very much for your reply.  OK it work correctly while encrypt and decrypt with Delphi 2010 Thanks!.  But when encrypt with Php and try to decrypt with delphi or Encrypt with Delphi and try to decrypt with Php it does not work.

Php Tested script at:
http://208.109.139.169/delphiphp/PhpCode/index.php

Experts can edit and test cript run on website above:
ftp host address:    208.109.139.169
User name:   delphiphp
Password:    Dphp2010
0
 
LVL 24

Expert Comment

by:jimyX
ID: 35135699
I can't access that link!
0
 

Author Comment

by:charin1904
ID: 35136209
Please try..

To View:
http://www.siambinary.com/delphiphp/PhpCode/index.php

To Edit:
ftp host address:    ftp.siambinary.com
User name:   delphiphp
Password:    Dphp2010
0
 
LVL 33

Assisted Solution

by:Slick812
Slick812 earned 250 total points
ID: 35139455
greetings charin1904, , I have looked at the code for  function TeaEncrypt( )  in the DelphiCode-updated.zip, , and in the code for  function TeaEncrypt( )  in the original question which I posted, the only change I could see was the pointer reference to the input string -
pTa := PByte(PChar(InStr));
      changed to -
pTa := PByte(PansiChar(InStr));

although I did not go through it line by line. I can not run the 2010 Delphi code, I do not have or use Delphi 2010. . .
When I tested this the PHP and Delphi functions, both encrypt and decrypt using the HEX strings as output, worked in both directions (php to delphi, , and delphi to php), from your comments, the delphi functions work for a delphi only run, and the PHP functions work for a PHP only run, but does not work for a Delphi output to a PHP input run.
If this is the case, I am unsure about how to go about debugging this, since the Delphi code seems unchanged, and the PHP code is likely the same also?

Please consider some encryption Factors, the Keys must be Identical , the Key Arrays in this case, and the verify arrays must be the same.
It looks like they are the same in the code that I have seen, so That may not be it?

I really do not understand why someone would place the key and verify array ini in the form ini function? shouldn't you set the key in the same function you call the TeaEncrypt( ).

Anyway, if you have the time or inclination, you might change the key and verify in each for testing as in -

     for php
$aryK = array(123,210,127,66,190,15,77,95);
$aryVr = array(48,162,251);


      for delphi
procedure TForm1.FormCreate(Sender: TObject);
begin
VAry[0] := 48;
VAry[1] := 162;
VAry[2] := 251;

aryKey[0] := 123;
aryKey[1] := 210;
aryKey[2] := 127;
aryKey[3] := 66;
aryKey[4] := 190;
aryKey[5] := 15;
aryKey[6] := 77;
aryKey[7] := 95;
end;


and then, run the PHP and Delphi  functions TeaEncrypt( ) , with the same input, maybe this input string -
'@@@@@@@@'

as in -
$bo1 = '@@@@@@@@';

, with the same keys, verify and input string, the hex output in both php and delphi should be the same, so compare the two outputs (look at them) and see if they are the same.

if they are not the same you may have to comment out different sections on the php and delphi functions for debugging, and try to isolate which section is causing the variance.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 24

Expert Comment

by:jimyX
ID: 35139593
Charin, the links are still not accessible.
0
 

Author Comment

by:charin1904
ID: 35139837
Slick812.. Oh... So difficulty..,  for now I think I need only base64_encode and base64_decode function that can run on Delphi 2010 and Php with same output.  

@jimyX,  which link you can't access

http://www.siambinary.com/delphiphp/PhpCode/index.php
or
ftp.siambinary.com
0
 
LVL 24

Expert Comment

by:jimyX
ID: 35140106
Both of them.
I get "time out" for the first, and "connection was reset" for the second.

This variance might be due to nonconformity in the coding between the php and Delphi. That's the only reason that you can get different result for using same key and text (i.e. if it was the same sequence of math and codes the result will always be the same).

Now the point is to know which is correct the php or the Delphi. You may use the Delphi component from the link below and encode/decode any text and match its result by using the code in question to find out which one is in conformity with it.
http://www.cityinthesky.co.uk/opensource/DCPcrypt
0
 

Accepted Solution

by:
charin1904 earned 0 total points
ID: 35140144
I think I got some solution now. Thank you very much for jimyX and Slick812.

---------------------------
I'll delete this question since have my private data.  Thanks again!
0
 

Author Closing Comment

by:charin1904
ID: 35174542
I got some solution now. Thank for all!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
xampp tool 12 31
unset shopping cart session 15 33
How do I randomize photo images before i move them to the path file? 9 23
array_values - reorder after unset? 5 14
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video teaches users how to migrate an existing Wordpress website to a new domain.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now