How to add/remove PKCS7 padding from an AES encrypted string?

前端 未结 3 540
慢半拍i
慢半拍i 2020-11-22 16:47

I\'m trying to encrypt/decrypt a string using 128 bit AES encryption (ECB). What I want to know is how I can add/remove the PKCS7 padding to it. It seems that the Mcrypt ext

3条回答
  •  耶瑟儿~
    2020-11-22 17:04

    Just call the following function after you decrypt the data

    function removePadding($decryptedText){
        $strPad = ord($decryptedText[strlen($decryptedText)-1]);
        $decryptedText= substr($decryptedText, 0, -$strPad);
        return $decryptedText;
    }
    

提交回复
热议问题