Solved

Rijndael 128 bit Encryption with Delphi and PHP - 2

Posted on 2011-03-14
10
1,334 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

746 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

13 Experts available now in Live!

Get 1:1 Help Now