DES Encryption in PHP and C#

前端 未结 2 1615
走了就别回头了
走了就别回头了 2020-12-10 22:56

I\'m trying to achive the same DES encription that I\'ve in an C# code but in PHP.

The C# code looks like the following:

public static string Encript         


        
相关标签:
2条回答
  • Check your padding. PHP internally pads the data to be encrypted with binary NULLs \x00 by default which is definitively not the default padding mode in .NET (most likely they use PKCS7 padding by default).

    0 讨论(0)
  • 2020-12-10 23:46

    Thank you very much guys. Helped me with same problem. PKCS7 padding here: How to add/remove PKCS7 padding from an AES encrypted string? just change ecb to cbc

    here is a short snapshot i used:

    $key = "29393651";
    $iv = $key;
    $pass_enc = $mypassword;
    $block = mcrypt_get_block_size('des', 'cbc');
    $pad = $block - (strlen($pass_enc) % $block);
    $pass_enc .= str_repeat(chr($pad), $pad);
    $pass_enc = mcrypt_encrypt(MCRYPT_DES, $key, $pass_enc, MCRYPT_MODE_CBC, $iv);
    $pass_enc = base64_encode ($pass_enc);
    
    0 讨论(0)
提交回复
热议问题