码迷,mamicode.com
首页 > Web开发 > 详细

[李景山php]每天laravel-20160829|McryptEncrypter-3

时间:2016-06-14 12:14:56      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:function   return   

/**
     * Run the mcrypt decryption routine for the value.
     *
     * @param  string  $value
     * @param  string  $iv
     * @return string
     *
     * @throws \Illuminate\Contracts\Encryption\DecryptException
     */
    protected function mcryptDecrypt($value, $iv)
    {
        try {
            return mcrypt_decrypt($this->cipher, $this->key, $value, MCRYPT_MODE_CBC, $iv);
        } catch (Exception $e) {
            throw new DecryptException($e->getMessage());
        }
    }//run function to decryption routine
   // this is a wrap about the mcrypt_decrypt

    /**
     * Add PKCS7 padding to a given value.
     *
     * @param  string  $value
     * @return string
     */
    protected function addPadding($value)
    {
        $pad = $this->block - (strlen($value) % $this->block);// this is a number

        return $value.str_repeat(chr($pad), $pad);// get this wale repeat this
    }// bad pad function

    /**
     * Remove the padding from the given value.
     *
     * @param  string  $value
     * @return string
     */
    protected function stripPadding($value)
    {
        $pad = ord($value[($len = strlen($value)) - 1]);

        return $this->paddingIsValid($pad, $value) ? substr($value, 0, $len - $pad) : $value;
    }// remove the padding from the given value.
   // check this value

    /**
     * Determine if the given padding for a value is valid.
     *
     * @param  string  $pad
     * @param  string  $value
     * @return bool
     */
    protected function paddingIsValid($pad, $value)
    {
        $beforePad = strlen($value) - $pad;

        return substr($value, $beforePad) == str_repeat(substr($value, -1), $pad);
    }// check pad valid

    /**
     * Get the IV size for the cipher.
     *
     * @return int
     */
    protected function getIvSize()
    {
        return mcrypt_get_iv_size($this->cipher, MCRYPT_MODE_CBC);
    }// get the iv size

    /**
     * Get the random data source available for the OS.
     *
     * @return int
     */
    protected function getRandomizer()// get the random
    {
        if (defined(‘MCRYPT_DEV_URANDOM‘)) {
            return MCRYPT_DEV_URANDOM;
        }

        if (defined(‘MCRYPT_DEV_RANDOM‘)) {
            return MCRYPT_DEV_RANDOM;
        }

        mt_srand();

        return MCRYPT_RAND;
    }
}


本文出自 “专注php” 博客,请务必保留此出处http://jingshanls.blog.51cto.com/3357095/1788994

[李景山php]每天laravel-20160829|McryptEncrypter-3

标签:function   return   

原文地址:http://jingshanls.blog.51cto.com/3357095/1788994

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!