?
Solved

Rijndael 128 bit Encryption with Delphi and PHP - 2

Posted on 2011-03-14
10
Medium Priority
?
1,387 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 24

Assisted Solution

by:jimyX
jimyX earned 1000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 34

Assisted Solution

by:Slick812
Slick812 earned 1000 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
 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

649 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