php des 对称加解密类
<?php header("Content-Type: text/html;charset=utf-8"); /** * des 对称加解密 */ class des { private $key = ''; private $cipher = MCRYPT_DES; //加解密算法 private $modes = MCRYPT_MODE_ECB; //算法模式 private $iv = ''; //初始化向量 /** * 密钥 */ public function __construct($key) { $this->key = $key; $this->iv = mcrypt_create_iv(mcrypt_get_iv_size($this->cipher,$this->modes),MCRYPT_RAND); } /** * 加密 */ public function encrypt($input) { return mcrypt_encrypt($this->cipher,$this->key,$input,$this->modes,$this->iv); } /** * 解密 */ public function decrypt($input) { return mcrypt_decrypt($this->cipher,$this->key,$input,$this->modes,$this->iv); //解密函数 } } $des = new des(100); $a = $des->encrypt('郭海明'); echo $des->decrypt($a);