implementing dot-net DES encryption by php
| From: | Ali Asghar Toraby Parizy | Date: | Thu, 16 Jun 2011 23:38:36 +0000 |
| Subject: | implementing dot-net DES encryption by php | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-313572@lists.php.net to get a copy of this message | ||
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ضt5OWہا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ضt5OWہا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.