2017-05-31 104 views
1

我试图按照CI的3个文档有关加密https://codeigniter.com/userguide3/libraries/encryption.html#setting-your-encryption-key
我应用指令的指令,但它不会让漂亮输出像我想,这里是标准的代码动态加密密钥

$this->load->library('encryption'); 
$key = $this->encryption->create_key(16); 
// Get a hex-encoded representation of the key: 
$key = bin2hex($this->encryption->create_key(16)); 

// Put the same value in your config with hex2bin(), 
// so that it is still passed as binary to the library: 
$config['encryption_key'] = hex2bin(<your hex-encoded key>); 

,但我得到这个错误 error config

如何解决这个问题?或者我正在写一些错误的代码?

+1

$ this'''是你的控制器类的一个实例。你不能在配置中使用它。你有类似'''$ CI =&get_instance();'''的实例并调用'''$ CI-> load-> library('encryption'); $关键= $ CI->加密 - > create_key(16);''' – kishor10d

+1

我觉得你是写在'''config.php'''的代码,而不是编写代码的控制器。 – kishor10d

+0

为了您的笨ENC关键https://randomkeygen.com/ – user4419336

回答

0

如果您使用加密类,则必须设置加密密钥。和动态加密密钥必须对config.php文件

//单个加密密钥
$配置[“encryption_key”] =“”设置不可分割控制器file.single加密密钥被设置;

//动态加密密钥 $ this-> load-> library('encryption'); //加载控制器中的加密库

$ key = bin2hex($ this-> encryption-> create_key(16));

$ config ['encryption_key'] = hex2bin();