亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

目錄 搜索
歡迎 目錄 快速參考圖 基本信息 服務(wù)器要求 許可協(xié)議 變更記錄 關(guān)于CodeIgniter 安裝 下載 CodeIgniter 安裝指導(dǎo) 從老版本升級 疑難解答 介紹 開始 CodeIgniter 是什么? CodeIgniter 速記表 支持特性 應(yīng)用程序流程圖 模型-視圖-控制器 架構(gòu)目標(biāo) 教程 內(nèi)容提要 加載靜態(tài)內(nèi)容 創(chuàng)建新聞條目 讀取新聞條目 結(jié)束語 常規(guī)主題 CodeIgniter URL 控制器 保留字 視圖 模型 輔助函數(shù) 使用 CodeIgniter 類庫 創(chuàng)建你自己的類庫 使用 CodeIgniter 適配器 創(chuàng)建適配器 創(chuàng)建核心系統(tǒng)類 鉤子 - 擴(kuò)展框架的核心 自動裝載資源 公共函數(shù) URI 路由 錯誤處理 緩存 調(diào)試應(yīng)用程序 以CLI方式運行 管理應(yīng)用程序 處理多環(huán)境 PHP替代語法 安全 開發(fā)規(guī)范 類庫參考 基準(zhǔn)測試類 日歷類 購物車類 配置類 Email 類 加密類 文件上傳類 表單驗證詳解 FTP 類 圖像處理類 輸入類 Javascript 類 語言類 裝載類 遷移類 輸出類 分頁類 模板解析器類 安全類 Session 類 HTML 表格類 引用通告類 排版類 單元測試類 URI 類 User-Agent 類 表單驗證 XML-RPC 和 XML-RPC 服務(wù)器 Zip 編碼類 緩存適配器 適配器參考 適配器 數(shù)據(jù)庫類 Active Record 類 數(shù)據(jù)庫緩存類 自定義函數(shù)調(diào)用 數(shù)據(jù)庫配置 連接你的數(shù)據(jù)庫 數(shù)據(jù)庫快速入門例子代碼 字段數(shù)據(jù) 數(shù)據(jù)庫維護(hù)類 查詢輔助函數(shù) 數(shù)據(jù)庫類 查詢 生成查詢記錄集 表數(shù)據(jù) 事務(wù) 數(shù)據(jù)庫工具類 JavaScript類 輔助函數(shù)參考 數(shù)組輔助函數(shù) CAPTCHA 輔助函數(shù) Cookie Helper 日期輔助函數(shù) 目錄輔助函數(shù) 下載輔助函數(shù) Email 輔助函數(shù) 文件輔助函數(shù) 表單輔助函數(shù) HTML輔助函數(shù) Inflector 輔助函數(shù) 語言輔助函數(shù) 數(shù)字輔助函數(shù) 路徑輔助函數(shù) 安全輔助函數(shù) 表情輔助函數(shù) 字符串輔助函數(shù) 文本輔助函數(shù) 排版輔助函數(shù) URL 輔助函數(shù) XML 輔助函數(shù)
文字

CodeIgniter 用戶指南 版本 2.1.0

編輯文檔、查看近期更改請 登錄 或 注冊  找回密碼
查看原文

加密類

數(shù)據(jù)加密類提供了兩種數(shù)據(jù)加密方式。 It uses a scheme that either compiles the message using a randomly hashed bitwise XOR encoding scheme, or is encrypted using the Mcrypt library. If Mcrypt is not available on your server the encoded message will still provide a reasonable degree of security for encrypted sessions or other such "light" purposes. If Mcrypt is available, you'll be provided with a high degree of security appropriate for storage.

設(shè)置你的密鑰

密鑰實際上是一些會控制密碼加密過程并且允許被加密的字串被解碼的信息片段。實際上,你選擇的密鑰會提供一個唯一的方法來解密一些被加密的數(shù)據(jù),所以你需要非常謹(jǐn)慎的設(shè)置你的密鑰,如果你想給一些固定的數(shù)據(jù)加密的話,你最好不要更改這個密鑰。

很自然,你需要非常小心的保守你的密鑰。如果某人對您的密鑰能夠存取,那么數(shù)據(jù)將會很容易地被解碼。如果您的服務(wù)器不完全在的您的控制之下而想保證數(shù)據(jù)安全是不可能的,因此您可以在使用它之前仔細(xì)地想一下要求高安全存放信用卡數(shù)字對象的方法。

為了發(fā)揮加密算法的最大優(yōu)勢,你的解密密鑰需要被設(shè)置為 32 個字符長度(128 位)。你可以設(shè)置一個編造的隨機字符串作為你的密鑰,最好包括數(shù)字、大寫字母、小寫字母。你的密鑰不能設(shè)置為一個簡單的文本字符串。為了被安全可靠的加密,它也有一個隨機的可能性。

你的密鑰可以放在 application/config/config.php 文件中,你也可以自己設(shè)置一個存儲機制用于數(shù)據(jù)的加密和解密。

為了在 application/config/config.php 文件中保存你的密鑰,打開文件設(shè)置一下:

$config['encryption_key'] = "YOUR KEY";

消息長度

知道加密信息的長度會是原來函數(shù)長度的 2.6 倍是很重要的。如果你加密這個字符串“my super secret data”,它的長度是 21 個字符,所以你加密后的字符串的長度大概是 55 個字符(我們說它是粗糙的,因為編碼的字符串長度增量 64 位并非是線性增長的),當(dāng)你選擇你的數(shù)據(jù)存儲機制的時候一定要記住這一點。例如,Cookie 可以占用 4k 的數(shù)據(jù)空間。

初始化類

在 Codeigniter 中,像大多數(shù)其他的類一樣,加密類也需要在你的控制器函數(shù)中用 $this->load->library 函數(shù)加載:

$this->load->library('encrypt');

一旦被加載,加密類庫就可以這樣使用:$this->encrypt

$this->encrypt->encode()

執(zhí)行數(shù)據(jù)加密并返回一個字符串。例如:

$msg = 'My secret message';

$encrypted_string = $this->encrypt->encode($msg);

如果你不想在你的配置文件中使用一個密鑰,你可以通過第二個參數(shù)隨意設(shè)置你的密鑰。

$msg = 'My secret message';
$key = 'super-secret-key';

$encrypted_string = $this->encrypt->encode($msg, $key);

$this->encrypt->decode()

解密一個已加密的字符串。例如:

$encrypted_string = 'APANtByIGI1BpVXZTJgcsAG8GZl8pdwwa84';

$plaintext_string = $this->encrypt->decode($encrypted_string);

You can optionally pass your encryption key via the second parameter if you don't want to use the one in your config file:

$msg = 'My secret message';
$key = 'super-secret-key';

$encrypted_string = $this->encrypt->decode($msg, $key);

$this->encrypt->set_cipher();

允許你設(shè)置一個 Mcrypt 算法。默認(rèn)使用 MCRYPT_RIJNDAEL_256。例如:

$this->encrypt->set_cipher(MCRYPT_BLOWFISH);

請訪問 php.net 看一下可用的算法。

如果你想手動測試一下你的服務(wù)器是否支持 Mcrypt,你可以使用:

echo ( ! function_exists('mcrypt_encrypt')) ? 'Nope' : 'Yup';

$this->encrypt->set_mode();

允許你設(shè)置一個 Mcrypt 模式。默認(rèn)使用 MCRYPT_MODE_CBC。例如:

$this->encrypt->set_mode(MCRYPT_MODE_CFB);

請訪問 php.net 看一下可用的模式。

$this->encrypt->sha1();

SHA1 編碼函數(shù)。提供一個字符串,然后它返回一個 160 位的 Hash 信息。說明:SHA1,就像 MD5 一樣不可解密。例如:

$hash = $this->encrypt->sha1('Some string');

許多 PHP 安裝程序默認(rèn)都支持 SHA1,所以你可以很簡單的使用它的原始函數(shù)進(jìn)行加密:

$hash = sha1('Some string');

如果你的服務(wù)器不支持 SHA1,你可以使用別人提供的函數(shù)。

$this->encrypt->encode_from_legacy($orig_data, $legacy_mode = MCRYPT_MODE_ECB, $key = '');

Enables you to re-encode data that was originally encrypted with CodeIgniter 1.x to be compatible with the Encryption library in CodeIgniter 2.x. It is only necessary to use this method if you have encrypted data stored permanently such as in a file or database and are on a server that supports Mcrypt. "Light" use encryption such as encrypted session data or transitory encrypted flashdata require no intervention on your part. However, existing encrypted Sessions will be destroyed since data encrypted prior to 2.x will not be decoded.

Why only a method to re-encode the data instead of maintaining legacy methods for both encoding and decoding? The algorithms in the Encryption library have improved in CodeIgniter 2.x both for performance and security, and we do not wish to encourage continued use of the older methods. You can of course extend the Encryption library if you wish and replace the new methods with the old and retain seamless compatibility with CodeIgniter 1.x encrypted data, but this a decision that a developer should make cautiously and deliberately, if at all.

$new_data = $this->encrypt->encode_from_legacy($old_encrypted_string);
Parameter Default Description
$orig_data n/a The original encrypted data from CodeIgniter 1.x's Encryption library
$legacy_mode MCRYPT_MODE_ECB The Mcrypt mode that was used to generate the original encrypted data. CodeIgniter 1.x's default was MCRYPT_MODE_ECB, and it will assume that to be the case unless overridden by this parameter.
$key n/a The encryption key. This it typically specified in your config file as outlined above.

?

翻譯貢獻(xiàn)者: baiyuxiong, Hex, qixingyue, zhupeng
最后修改: 2011-04-06 23:38:13
上一篇: 下一篇: