本篇文章给大家带来的内容是关于php中des加解密的代码示例,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
test.php测试文件
'AbcdefghijklmnopqrstuvwX','secretcode'=>'Abcdefgh']; $encode = $des->encode($data, $conf); print_r($encode); echo "
"; $decode = $des->decode($encode,$conf); print_r($decode); ?>
Des.php
jQuery自动滚动五屏图片通栏代码,带左右按钮切换图片,鼠标移到图片后图片高亮显示,点击会显示带阴影的大图。兼容主流浏览器,php中文网推荐下载! 使用方法: 1、head区域引用文件lrtk.css及js库 2、在文件中加入区域代码 3、复制images文件夹里的图片到相应的路径
encode($data, $configKey["appkey"], $configKey["secretcode"]);
}
public static function decode($data, $configKey) {
$tripleDes = new TripleDES();
return $tripleDes->decode($data, $configKey["appkey"], $configKey["secretcode"]);
}
public static function encodeArr($data, $configKey) {
$data = json_encode($data);
return self::encode($data, $configKey);
}
public static function decodeArr($data, $configKey) {
$res = self::decode($data, $configKey);
return json_decode($res,true);
}
}TripleDES.php
strlen($text))
return false;
if (strspn($text, chr($pad), strlen($text) - $pad) != $pad)
return false;
return substr($text, 0, -1 * $pad);
}
public static function encryptText($plain_text, $key, $iv) {
$padded = TripleDES::pkcs5Pad($plain_text, mcrypt_get_block_size(MCRYPT_TRIPLEDES, MCRYPT_MODE_CBC));
return mcrypt_encrypt(MCRYPT_TRIPLEDES, $key, $padded, MCRYPT_MODE_CBC, $iv);
}
public static function decryptText($cipher_text, $key, $iv) {
if(function_exists('mcrypt_decrypt')){
$plain_text = mcrypt_decrypt(MCRYPT_TRIPLEDES, $key, $cipher_text, MCRYPT_MODE_CBC, $iv);
}else{
$plain_text = openssl_decrypt($cipher_text, 'DES-EDE3-CBC',$key, OPENSSL_NO_PADDING,$iv);
}
return TripleDES::pkcs5Unpad($plain_text);
}
public static function decode($cipher_text, $key, $iv) {
$cipher_text = base64_decode($cipher_text);
$cipher_text = TripleDES::decryptText($cipher_text, $key, $iv);
return $cipher_text;
}
public static function encode($cipher_text, $key, $iv) {
$cipher_text = TripleDES::encryptText($cipher_text, $key, $iv);
return base64_encode($cipher_text);
}
}【推荐课程:PHP视频教程】










