phalcon: crypt-encrypt/decrypt用法

phalcon:crypt加密与解密

可以在入口文件index.php进行配置,也可以不配置:

$di->set(‘crypt‘, function(){
    $crypt = new \Phalcon\Crypt();
    return $crypt;
}, true);

或者:

$di[‘crypt‘] = function(){
   $crypt=new \Phalcon\Crypt();
   return $crypt;
};

关于调用:
$this->crypt;
或者
$this->di[‘crypt‘];
或者
$this->di->crypt;

  

加密解密代码:

        $key = "le password";
        $password = "this is a secret text";

            //加密
            $crypt = new \Phalcon\Crypt();
            $encrypted = $crypt->encrypt($password, $key);
            echo $encrypted;

            //解密
            $crypt = new \Phalcon\Crypt();
            $encrypted = $crypt->encrypt($password, $key);
            //
            $password = $crypt->decrypt($encrypted, $key);
            echo $password;

  

64位的加密解密方便url传输:

      $crypt = new \Phalcon\Crypt();
       // $crypt->setCipher(‘blowfish‘);
        $key = "le password";
        $password = "this is a sicret text";

        //加密
        $encrypted = $crypt->encryptBase64($password, $key);
        echo $encrypted;

        echo "<br>";

       //解密
        $password = $crypt->decryptBase64($encrypted, $key);
        echo $password;

  

时间: 2024-10-05 19:21:58

phalcon: crypt-encrypt/decrypt用法的相关文章

A very simple C++ module to encrypt/decrypt strings based on B64 and Vigenere ciper.

https://github.com/philipperemy/easy-encryption Easy Encryption A very simple yet powerful standalone C++ module (API) to encrypt/decrypt strings based on B64 and Vigenere ciper (symmetric cipher). It works as follows: Alice encodes in base64 the mes

Phalcon 加密解密组件

2.40 Encryption/Decryption 加密/解密 Phalcon provides encryption facilities via thePhalcon\Crypt component. This class offers simple object-oriented wrappers to themcrypt php's encryption library. By default, this component provides secure encryption usi

[PHP] Phalcon操作示范

这篇内容将对下列操作进行示范: Insert.Select.Update.Calculation.Transaction.models advanced.dev-tools.cookies [ Insert ] (1) // 模型内操作,data是['字段'=>'值']的一维数组. $bool = $this->save($data); return $bool; (2) // static $db = \Phalcon\Di::getDefault()->getShared('db')

Phalcon Cookie管理

2.27 Cookies Management cooke管理 Cookies are very useful way to store small pieces of data in the client that can be retrieved even if the user closes his/her browser.Phalcon\Http\Response\Cookiesacts as a global bag for cookies. Cookies are stored in

学渣也要搞 laravel(4)—— 服务 加解密篇

使用 Crypt::encrypt() 对数据进行加密,[注意要引入 use Illuminate\Support\Facades\Crypt;; ] 简单的做个测试: 先分配一个路由: 1 Route::get('test','[email protected]'); 例子: 1 public function crypt(){ 2 $pswd = '123456'; 3 $pswd_lock = Crypt::encrypt($pswd);//加密$pswd 4 echo $pswd_loc

安全和加密——openssl及自建CA

一.对称加密算法 对称加密:加密和解密使用共用一个秘钥 特点 加密.解密使用同一个秘钥,效率高: 将原始数据分割成固定大小的块,逐个进行加密 缺点 密钥过多,密钥需要分发 数据来源无法确认 1. 使用gpg实现对称加密 对称加密文件 gpg -c file 生成 file.gpg 在另一台主机上解密 gpg-o file -d file.gpg 2. 使用gpg工具实现公钥加密 在B主机上用公钥加密,在A主机上解密 在A主机上生成公钥密钥对 gpg --gen-key // 生成公钥密钥对 需要

Cryptography - JavaScript 加密算法库

Example 1: The following example uses aes function. <script type="text/javascript" src="http://cryptojs.altervista.org/api/functions_cryptography.js"></script> <script type="text/javascript"> var Crypt = new

2、后台超级管理员完善密码修改功能

(1)添加路由(在admin.login中间件) Route::any('pass','[email protected]'); (2) IndexController.php中添加pass方法 注意Input.Crypt.User的引用 先判断新密码是否符合要求以及确认密码,此时若错误,返回的是对象: 之后再查询数据库,判断原密码是否正确,此时错误返回的是字符串 use App\Http\Model\User; use Illuminate\Support\Facades\Input; use

Laravel之加密解密/日志/异常处理及自定义错误

一.加密解密 1.加密Crypt::encrypt($request->secret) 2.解密try { $decrypted = Crypt::decrypt($encryptedValue);} catch (DecryptException $e) { //} 二.日志 1.配置文件config/app.php 中的debug 配置选项控制浏览器显示的错误详情数量.默认情况下,该配置选项被设置在.env 文件中的环境变量APP_DEBUG .对本地开发而言,你应该设置环境变量APP_DE