2017-05-31 102 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();