批改状态:未批改
老师批语:
今天主要有两方面的内容,redis的基本知识(安装,基本操作,哈希表的操作),aes加密技术在php的实现
redis基本操作
安装
网上找的教程,安装起来比较简单,同时安装了图形客户端
操作
set 可以设置键值对 get可以获取 hset 设置哈希表(键值数组)的键 字段 值 hget获取 hgetall获取键下的所有字段和值
AES加密技术
php5
<?php
$str = "yihang.web11";
//aes类实例
$aes = new AES();
$enAes = $aes->encrypt($str);
$deAes = $aes->decrypt($enAes);
echo $enAes;
echo '<hr>';
echo $deAes;
//AES加密解密类
class AES{
//密钥
private $skey = "fuckfuckfuckfuck";
//cbc模式 偏移量
public function __construct()
{
define('IV', 'pickbickdicksick');
}
//加密 $str需要加密的字符串、明文
public function encrypt($str){
$encrypt_str = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->skey, $str, MCRYPT_MODE_CBC, IV);
return base64_encode($encrypt_str);
}
//解密 $str需要揭秘的数据 密文
public function decrypt($str){
$str = base64_decode($str);
$decrypt_str = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->skey, $str, MCRYPT_MODE_CBC, IV);
return $decrypt_str;
}
}点击 "运行实例" 按钮查看在线实例
php7.2 开启openssl
<?php
$str = "jj.io";
$ase = new AES_OPENSSL();
$en_res = $ase->encrypt($str);
$de_res = $ase->decrypt($en_res);
echo $en_res;
echo '<hr>';
echo $de_res;
//php7.2
class AES_OPENSSL {
public function __construct()
{
//加密方式
$this->cipher = 'aes-128-gcm';
//// options 是以下标记的按位或: OPENSSL_RAW_DATA 、OPENSSL_ZERO_PADDING
$this->options = 0;
//使用 AEAD 密码模式(GCM 或 CCM)时传引用的验证标签
$this->tag = '';
//获得该加密方式的iv长度
$ivLength = openssl_cipher_iv_length($this->cipher);
//非null的初始化向量
$this->iv = openssl_random_pseudo_bytes($ivLength);
//生成相对应长度的伪随机字符串初始化向量
$this->skey = 'dookdookdookdook';
}
//加密
public function encrypt($str){
$enText = openssl_encrypt($str, $this->cipher, $this->skey, $this->options, $this->iv, $this->tag);
return $enText;
}
//解密
public function decrypt($str){
$deText = openssl_decrypt($str, $this->cipher, $this->skey, $this->options, $this->iv, $this->tag);
return $deText;
}
}点击 "运行实例" 按钮查看在线实例
总结
加密技术是能够解密的才称之为加密技术,主流的有DSE和ASE,DSE被破解所以现在都有ASE。MD5不能算加密技术。
redis技术是内存数据库,特点就是读取数据快,不过进程结束数据就没有了
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号