DES Encryption in PHP and C#

前端 未结 2 1620
走了就别回头了
走了就别回头了 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条回答
  •  感动是毒
    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);
    

提交回复
热议问题