<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # Encryption/Decryption Phalcon通過[Phalcon\\Crypt](http://docs.iphalcon.cn/api/Phalcon_Crypt.html)組件提供了加密和解密工具。這個類提供了對PHP[openssl](http://www.php.net/manual/en/book.openssl.php)的封裝。 默認情況下這個組件使用AES-256-CFB。 > You must use a key length corresponding to the current algorithm. For the algorithm used by default it is 32 bytes. ## 基本使用 這個組件極易使用: ~~~ <?php use Phalcon\Crypt; // Create an instance $crypt = new Crypt(); $key = "This is a secret key (32 bytes)."; $text = "This is the text that you want to encrypt."; $encrypted = $crypt->encrypt($text, $key); echo $crypt->decrypt($encrypted, $key); ~~~ 也可以使用同一實例加密多次: ~~~ <?php use Phalcon\Crypt; // 創建實例 $crypt = new Crypt(); $texts = [ "my-key" => "This is a secret text", "other-key" => "This is a very secret", ]; foreach ($texts as $key => $text) { // 加密 $encrypted = $crypt->encrypt($text, $key); // 解密 echo $crypt->decrypt($encrypted, $key); } ~~~ ## 加密選項(Encryption Options) 下面的選項可以改變加密的行為: | 名稱 | 描述 | | --- | --- | | Cipher | cipher是libmcrypt提供支持的一種加密算法。 查看這里[here](http://www.php.net/manual/en/function.openssl-get-cipher-methods.php) | 例子: ~~~ <?php use Phalcon\Crypt; // 創建實例 $crypt = new Crypt(); // 使用 blowfish $crypt->setCipher("bf-cbc"); $key = "le password"; $text = "This is a secret text"; echo $crypt->encrypt($text, $key); ~~~ ## 提供 Base64(Base64 Support) 為了方便傳輸或顯示我們可以對加密后的數據進行[base64](http://www.php.net/manual/en/function.base64-encode.php)轉碼: ~~~ <?php use Phalcon\Crypt; // 創建實例 $crypt = new Crypt(); $key = "le password"; $text = "This is a secret text"; $encrypt = $crypt->encryptBase64($text, $key); echo $crypt->decryptBase64($encrypt, $key); ~~~ ## 配置加密服務(Setting up an Encryption service) 你也可以把加密組件放入服務容器中這樣我們可以在應用中的任何一個地方訪問這個組件: ~~~ <?php use Phalcon\Crypt; $di->set( 'crypt', function () { $crypt = new Crypt(); // 設置全局加密密鑰 $crypt->setKey( "%31.1e$i86e$f!8jz" ); return $crypt; }, true ); ~~~ 然后,例如,我們可以在控制器中使用它了: ~~~ <?php use Phalcon\Mvc\Controller; class SecretsController extends Controller { public function saveAction() { $secret = new Secrets(); $text = $this->request->getPost("text"); $secret->content = $this->crypt->encrypt($text); if ($secret->save()) { $this->flash->success( "Secret was successfully created!" ); } } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看