implementing dot-net DES encryption by php

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi
I have a big problem.I've tried for 2 days but I haven't been able to solve
the problem yet. I need to implement dot-net DES encryption in php site.
I tired several solutions and the following code is the best that I've seen.
But it doesn't work perfect either.
----------------
Header("Content-disposition: attachment; filename=test.txt");
Header("Content-type: text/plain");
$key = "alidfsdf";
$iv = "asghasdr";
$buffer =
"0736f6a24766866a60e5a300e6f067aef5c2428a7c5ba59b1c2af2ec9289aaad6d7fd8345910fac94b99311d0487a02080665ed5a5f48b9a35093eed16eb8c38\nsdfgh";
$td = mcrypt_module_open('tripledes', '', 'cbc', '');
$key .= substr($key, 0, mcrypt_enc_get_key_size($td));
$block = mcrypt_get_block_size('tripledes', 'cbc');
$len = strlen($buffer);
$padding = $block - ($len % $block);
$buffer .= str_repeat(chr($padding),$padding);

if (mcrypt_generic_init($td, $key, $iv) != -1){
       $Result = mcrypt_generic($td, $buffer);
       mcrypt_generic_deinit($td);
       mcrypt_module_close($td);
  }
echo $Result;
----------------
this is the output of this php program:

âØPyÂfØt5OâWÛØKÚÛjÂÂLØ    [;ÂnâØÃ^uH
ÃLÚÂgâØâw~2ÚC cØÃIÙ7ââÃGâpÚØ:Â1ÙØ
qØYâzMÙÚâÙ    %`ÙÙØØufË ÙTâINÃÃ#>!ÃÂÃ<ÂØÂâØ2ØØâÂÙ8%

Output from c# application is here(using PaddingMode.PKCS7 and other default
settings):

âØPyÂfØt5OâWÛØKÚÛjÂÂLØ    [;ÂnâØÃ^uH
ÃLÚÂgâØâw~2ÚC cØÃIÙ7ââÃGâpÚØ:Â1ÙØ
qØYâzMÙÚâÙ    %`ÙÙØØufË ÙTâINÃÃ#>!ÃÂÃ<ÂØÂâØ2ØjÂÂn(VÂÃ
2Ø
Â

However they are like each other. But As you can see, the 16 last characters
are different.
I think there is a problem in $buffer .= str_repeat(*chr($padding)*
,$padding);
Please help me. I'm going to deliver it tomorrow.
Thanks for any help.

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux