Replacing JAVA with PHP for PKCS5 encryption

前端 未结 3 1385
抹茶落季
抹茶落季 2021-02-09 12:16

I have been tasked with replacing a legacy java system with something which runs PHP.

I am getting a little stuck on replacing the java cryptography with PHP code.

3条回答
  •  心在旅途
    2021-02-09 13:06

    You may want to look at http://us3.php.net/manual/en/ref.mcrypt.php#69782, but basically he implemented a DIY padding solution:

    function pkcs5_pad ($text, $blocksize) 
    { 
        $pad = $blocksize - (strlen($text) % $blocksize); 
        return $text . str_repeat(chr($pad), $pad); 
    } 
    

    That may be your best bet, but if you look at this comment, his suggestions on how to verify that each step is correct may be useful for you.

    https://stackoverflow.com/a/10201034/67566

    Ideally you should move away from DES and since this padding is going to be a problem in PHP, why not see if you can change the encryption algorithm to something less troublesome and more secure?

    To help you can show this page: http://www.ietf.org/rfc/rfc4772.txt, where it is succinctly expressed that DES is susceptible to brute force attacks, so has been deprecated and replaced with AES.

提交回复
热议问题