您当前的位置: 首页 >  php

漏刻有时

暂无认证

  • 0浏览

    0关注

    717博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

漏刻有时PHP授权封装加解密函数LockAuthority类

漏刻有时 发布时间:2021-01-31 13:20:28 ,浏览量:0

LockAuthority核心类
class LockAuthority
{
   
    /**
     * This was AES-128 / CBC / PKCS5Padding
     * return base64_encode string
     * @author Terry
     * @param string $plaintext
     * @param string $key
     * @return string
     */
    public static function AesEncrypt($plaintext, $key = null)
    {
   
        $plaintext = trim($plaintext);
        if ($plaintext == '') return '';
        @$size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);

        //PKCS5Padding
        $padding = $size - strlen($plaintext) % $size;
        // 添加Padding
        $plaintext .= str_repeat(chr($padding), $padding);

        @$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
        @$key = self::substr($key, 0, mcrypt_enc_get_key_size($module));
        $iv = str_repeat("\0", $size);      //java里面的16个空数组对应的是\0.
        /* Intialize encryption */
        @mcrypt_generic_init($module, $key, $iv);

        /* Encrypt data */
        @$encrypted = mcrypt_generic($module, $plaintext);

        /* Terminate encryption handler */
        @mcrypt_generic_deinit($module);
        @mcrypt_module_close($module);
        return base64_encode($encrypted);
    
关注
打赏
1661217259
查看更多评论
立即登录/注册

微信扫码登录

0.0360s