PHP script for DES/CBC/ with PKCS5Padding encryption and decryption

前端 未结 2 1955
轮回少年
轮回少年 2021-01-15 11:59

I would like to know in the following code if PKCS#5 padding is added ? If not how to add ?

$message = \"insert plaintext message here\";

$iv  = pack(\'H*\'         


        
2条回答
  •  耶瑟儿~
    2021-01-15 12:42

    No, it is not added. Unfortunately PHP / mcrypt uses zero padding until the message is N times the block size.

    To add PKCS#5 padding, use the formula:

    p = b - l % b
    

    Where l is the message length, b is the block size and % is the remainder operation. Then add p bytes with the value p to the end before performing the encryption.

提交回复
热议问题