您的位置:首页 > 编程语言 > PHP开发

[李景山php]每天laravel-20160827|McryptEncrypter-1

2016-06-12 09:10 591 查看
namespace Illuminate\Encryption;

use Exception;
use RuntimeException;
use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Contracts\Encryption\EncryptException;
use Illuminate\Contracts\Encryption\Encrypter as EncrypterContract;

/**
* @deprecated since version 5.1. Use Illuminate\Encryption\Encrypter.
*/
class McryptEncrypter extends BaseEncrypter implements EncrypterContract
{// use Mcrypt  Encrypter extends baseEncrypter
/**
* The algorithm used for encryption.
*
* @var string
*/
protected $cipher;// this is a algorithm used for encryption

/**
* The block size of the cipher.
*
* @var int
*/
protected $block;// block size about cipher

/**
* Create a new encrypter instance.
*
* @param  string  $key
* @param  string  $cipher
* @return void
*
* @throws \RuntimeException
*/
public function __construct($key, $cipher = MCRYPT_RIJNDAEL_128)
{
$key = (string) $key;// use parameter is key and cipher [algorithm]

if (static::supported($key, $cipher)) {
$this->key = $key;// key
$this->cipher = $cipher;// cipher
$this->block = mcrypt_get_iv_size($this->cipher, MCRYPT_MODE_CBC);// get the block
} else {
throw new RuntimeException('The only supported ciphers are MCRYPT_RIJNDAEL_128 and MCRYPT_RIJNDAEL_256.');
}// if wrong throw error
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: