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 =
$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);
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

…ز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¯ë

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)*
Please help me. I'm going to deliver it tomorrow.
Thanks for any help.

Reply via email to