Home  >  Article  >  php教程  >  二次加密,数据校验

二次加密,数据校验

PHP中文网
PHP中文网Original
2016-05-25 17:06:381349browse

二次加密,数据校验

用于二次加密,数据校验,也许md5已经足够了,不过在用户密码字段里,还是会经常看到这样的md5串: e10adc3949ba59abbe56e057f20f883e,经常开测试账号的人你懂的

<?php
$txt = "123456";// 原文
echo "txt={$txt}\r\n";
$key = "keyword";// 密钥,最好用ord后127以内的字符,且不要有字符重复
$encrpt = md5($txt);// md5后的密文
echo "md5={$encrpt}\r\n";

$j = 0;
$lk = strlen($key);
$lt = strlen($encrpt);

for($i = 0;$i < $lt;$i++){
  $j %= $lk;
  $sum = ord($encrpt[$i]) + ord($key[$j]);// 逐位拼接密钥
  $encrpt[$i] = dechex($sum % 16);// 对16求余后生成新的16进制数,并替换对应位置字符
  $j++;
}
echo "encrpt={$encrpt}";
?>

               

 以上就是二次加密,数据校验的内容,更多相关内容请关注PHP中文网(www.php.cn)!

   

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