PHP加密解密函数详解,加密解密函数详解
分享一个PHP加密解密的函数,此函数实现了对部分变量值的加密的功能。
加密代码如下:
/* *功能:对字符串进行加密处理 *参数一:需要加密的内容 *参数二:密钥 */ function passport_encrypt($str,$key){ //加密函数 srand((double)microtime() * 1000000); $encrypt_key=md5(rand(0, 32000)); $ctr=0; $tmp=''; for($i=0;$i<strlen($str);$i++){ $ctr=$ctr==strlen($encrypt_key)?0:$ctr; $tmp.=$encrypt_key[$ctr].($str[$i] ^ $encrypt_key[$ctr++]); } return base64_encode(passport_key($tmp,$key)); }
解密代码如下:
/* *功能:对字符串进行解密处理 *参数一:需要解密的密文 *参数二:密钥 */ function passport_decrypt($str,$key){ //解密函数 $str=passport_key(base64_decode($str),$key); $tmp=''; for($i=0;$i<strlen($str);$i++){ $md5=$str[$i]; $tmp.=$str[++$i] ^ $md5; } return $tmp; }
辅助函数:
/* *辅助函数 */ function passport_key($str,$encrypt_key){ $encrypt_key=md5($encrypt_key); $ctr=0; $tmp=''; for($i=0;$i<strlen($str);$i++){ $ctr=$ctr==strlen($encrypt_key)?0:$ctr; $tmp.=$str[$i] ^ $encrypt_key[$ctr++]; } return $tmp; }
使用如下所示:
$str='作者:余浩苗;电话:13611972365;电子邮件:123cvbz@163.com'; $key='hacker'; $encrypt=passport_encrypt($str,$key); $decrypt=passport_decrypt($encrypt,$key); echo '原文:',$str."<br><hr>"; echo '密文:',$encrypt."<br><hr>"; echo '译文:',$decrypt."<br><hr>";
以上就是为大家分享的php加密解密函数,希望大家喜欢,可以应用到自己的学习中。
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
Assassin's Creed Shadows: Seashell Riddle Solution
1 months agoByDDD
What's New in Windows 11 KB5054979 & How to Fix Update Issues
3 weeks agoByDDD
Where to find the Crane Control Keycard in Atomfall
1 months agoByDDD
How to fix KB5055523 fails to install in Windows 11?
2 weeks agoByDDD
InZoi: How To Apply To School And University
3 weeks agoByDDD

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1
Easy-to-use and free code editor

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
