php 加密解密字符串
/*********************************************************************
函数名称:encrypt
函数作用:加密解密字符串
使用方法:
加密 :encrypt('str','E','nowamagic');
解密 :encrypt('被加密过的字符串','D','nowamagic');
参数说明:
$string :需要加密解密的字符串
$operation:判断是加密还是解密:E:加密 D:解密
$key :加密的钥匙(密匙);
*********************************************************************/
function encrypt($string, $operation, $key = 'WMqsfPpS9hwyoJnFP')
{
$key = md5($key);
$key_length = strlen($key);
$string = $operation == 'D' ? base64_decode($string) : substr(md5($string . $key), 0, 8) . $string;
$string_length = strlen($string);
$rndkey = $box = array();
$result = '';
for ($i = 0; $i <= 255; $i++) {
$rndkey[$i] = ord($key[$i % $key_length]);
$box[$i] = $i;
}
for ($j = $i = 0; $i < 256; $i++) {
$j = ($j + $box[$i] + $rndkey[$i]) % 256;
$tmp = $box[$i];
$box[$i] = $box[$j];
$box[$j] = $tmp;
}
for ($a = $j = $i = 0; $i < $string_length; $i++) {
$a = ($a + 1) % 256;
$j = ($j + $box[$a]) % 256;
$tmp = $box[$a];
$box[$a] = $box[$j];
$box[$j] = $tmp;
$result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
}
if ($operation == 'D') {
if (substr($result, 0, 8) == substr(md5(substr($result, 8) . $key), 0, 8)) {
return substr($result, 8);
} else {
return '';
}
} else {
return str_replace('=', '', base64_encode($result));
}
}
php 加密解密字符串的更多相关文章
- PHP的加密解密字符串函数
程序中经常使用的PHP加密解密字符串函数 代码如下: /********************************************************************* 函数 ...
- Java加密解密字符串
http://www.cnblogs.com/vwpolo/archive/2012/07/18/2597232.html Java加密解密字符串 旧文重发:http://www.blogjava ...
- django删除表重建&修改用户密码&base64加密解密字符串&ps aux参数说明&各种Error例子
1.django的queryset不支持负索引 AssertionError: Negative indexing is not supported. 2.django向前端JavaScript传递列 ...
- PHP_加密解密字符串
PHP_加密解密字符串.php <?php //加解密字符串函数,可以加密中文 /* //加密 echo $encode = authcode('爱迪生', 'ENCODE', '3'); // ...
- PHP加密解密字符串
项目中有时我们需要使用PHP将特定的信息进行加密,也就是通过加密算法生成一个加密字符串,这个加密后的字符串可以通过解密算法进行解密,便于程序对解密后的信息进行处理. 最常见的应用在用户登录以及一些AP ...
- [DEncrypt] RSACryption--RSA加密/解密字符串 (转载)
点击下载 RSACryption.zip 这个类是关于加密,解密的操作,文件的一些高级操作1.RSACryption RSA 的密钥产生2.RSACryption RSA的加密函数3.RSACrypt ...
- .net core 使用MD5加密解密字符串
/// <summary> /// 加密 /// </summary> /// <param name="Text">要加密的文本</pa ...
- MD5 加密解密字符串
方法1: using System.Text; using System.Security.Cryptography; public string Hash(string toHash) { MD5C ...
- Asp.net,C# 纯数字加密解密字符串
也就是说加密后的数据不再是:N8lAaHMFtSAQgaf3+RUFng== 希望encryptedString是"1203877893704809384098328409234923840 ...
随机推荐
- JavaWeb学习总结(七)—HttpServletRequest
一.Request概述 request是Servlet.service()方法的一个参数,类型为javax.servlet.http.HttpServletRequest.在客户端发出每个请求时,服务 ...
- 【spring-quartz】 定时调度,时间设置
. CronTrigger时间格式配置说明 CronTrigger配置格式: 格式: [秒] [分] [小时] [日] [月] [周] [年] 序号 说明 是否必填 允许填写的值 允许的通配符 1 ...
- 聊天界面之气泡文本cell(一)
在实现qq聊天界面的过程中,使用UITableViewCell碰到了不少问题,这里还是记录一下以免遗忘. 气泡聊天cell的实现,网上最多的方法还是: 1.手动计算设置frame的值,文本的size使 ...
- PacBio & BioNano (Assembly and diploid architecture of an individual human genome via single-molecule technologies)
Assembly and diploid architecture of an individual human genome via single-molecule technologies 文章链 ...
- Dorado7检验器失效原因分析
应用场景: AutoForm1使用包含A.B两个字段的DataType1. A字段不允许为空,并且B字段取值true时A字段需要重新输入,B取其它值时A值不需重新录入. 实现方法:A字段添加了非空检验 ...
- Windows7睡眠后自动唤醒
笔者的电脑(Windows7 64位旗舰版)睡眠后,隔段时间后会自动唤醒.经两项配置后,解决了该问题. 1 禁用唤醒定时器 控制面板里进入"电源选项""更改计划设置&qu ...
- Working with Data » Getting started with ASP.NET Core and Entity Framework Core using Visual Studio » 增、查、改、删操作
Create, Read, Update, and Delete operations¶ 5 of 5 people found this helpful By Tom Dykstra The Con ...
- 【BZOJ 2243】染色 - 树链剖分+线段树
#include <cstdio> #include <cstring> #include <cstdlib> using namespace std; const ...
- html5日期转long
正确:日期,时间均是实时的 var inDate = $("#inDate").val().trim(); if(inDate != "") { inDate ...
- 谈谈JPA-01-概述
JPA和Hibernate的关系 JPA 是 hibernate 的一个抽象(就像JDBC和JDBC驱动的关系): JPA 是规范:JPA 本质上就是一种 ORM 规范,不是ORM 框架 —— 因为 ...