PHP DES加密解密 ECB 、pkcs5pkcs7

    xiaoxiao2021-03-25  256

    加密方式与http://tool.chacuo.net/cryptdes加密方式一样

    <?php echo '<br/><br/><br/>'; $key = '1234'; $jiami = encrypt('123',$key); echo $jiami.'<br/>'; echo decrypt($jiami,$key); //加密 function encrypt($str, $key){ $block = mcrypt_get_block_size('des', 'ecb'); $pad = $block - (strlen($str) % $block); $str .= str_repeat(chr($pad), $pad); return base64_encode(mcrypt_encrypt(MCRYPT_DES, $key, $str, MCRYPT_MODE_ECB) ); } //解密 function decrypt($sStr, $sKey) { $decrypted= mcrypt_decrypt( MCRYPT_DES, $sKey, base64_decode($sStr), MCRYPT_MODE_ECB ); $dec_s = strlen($decrypted); $padding = ord($decrypted[$dec_s-1]); $decrypted = substr($decrypted, 0, -$padding); return $decrypted; }

    结果:

    http://tool.chacuo.net/cryptdes网站结果:

    转载请注明原文地址: https://ju.6miu.com/read-560.html

    最新回复(0)