> 백엔드 개발 > PHP 튜토리얼 > PHP 암호화 방법 및 복호화 방법

PHP 암호화 방법 및 복호화 방법

炎欲天舞
풀어 주다: 2023-03-14 16:40:01
원래의
7660명이 탐색했습니다.

테스트 파일

test.php

<?php    
    echo "hello world.";
?>
로그인 후 복사

1. 암호화 방법:

<?php
/*
eval() 函数把字符串按照 PHP 代码来计算。该字符串必须是合法的 PHP 代码,且必须以分号结尾。
strtr() 字符替换 把字符串中的字符 "ia" 替换为 "eo":strtr("Hilla Warld","ia","eo");
*/
function T_rndstr($length = "") { //返回随机字符串
    $str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    if ($length == "") {
        return str_shuffle($str);
    } else {
        return substr(str_shuffle($str), -$length);
    }
}

$T_k1 = T_rndstr(); //随机密匙1
$T_k2 = T_rndstr(); //随机密匙2
$vstr = file_get_contents("./test.php"); //要加密的文件
$v1 = base64_encode($vstr);
$c = strtr($v1, $T_k1, $T_k2); //根据密匙替换对应字符
$c = $T_k1 . $T_k2 . $c;
//$qn变量功能下面会讲解
$isqs = 3;
if ($isqs == "1") { // 1 取随机字符串为变量名
    $q = T_rndstr(); // 随机字符串
    $q1 = substr($q, 2, 3);
    $q2 = substr($q, 10, 10);
    $q3 = substr($q, 20, 12);
    $q4 = substr($q, 30, 10);
    $q5 = substr($q, 40, 8);
    $q6 = substr($q, 5, 5);
} else if ($isqs == "2") { // 2 为小写l和1组成,开头必须是字母
    $q1 = "ll11l1l1";
    $q2 = "l1lll11l";
    $q3 = "ll1l1lll";
    $q4 = "l1lll1l1";
    $q5 = "l1l1ll11";
    $q6 = "ll111l1l";
} else { // 大写O与数字0组成基本变量
    $q1 = "O00O0O";
    $q2 = "O0O000";
    $q3 = "O0OO00";
    $q4 = "OO0O00";
    $q5 = "OO0000";
    $q6 = "O00OO0";
}
$keystr = urldecode("%6E1%7A%62%2F%6D%615%5C%76%740%6928%2D%70%78%75%71%79%2A6%6C%72%6B%64%679%5F%65%68%63%73%77%6F4%2B%6637%6A");
/* 字符串,里面必须要有变量所需的字符,比如 base64_decode
n1zb/ma5\vt0i28-pxuqy*6lrkdg9_ehcswo4+f37j
$q1 = base
$q3 = strtr
$q4 = substr
$q5 = 52 -> ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 长度
$q1 .= 64_decode -> base64_decode
*/
$s = &#39;$&#39; . $q6 . &#39;=urldecode("%6E1%7A%62%2F%6D%615%5C%76%740%6928%2D%70%78%75%71%79%2A6%6C%72%6B%64%679%5F%65%68%63%73%77%6F4%2B%6637%6A");
$&#39; . $q1 . &#39;=$&#39; . $q6 . &#39;{3}.$&#39; . $q6 . &#39;{6}.$&#39; . $q6 . &#39;{33}.$&#39; . $q6 . &#39;{30};
$&#39; . $q3 . &#39;=$&#39; . $q6 . &#39;{33}.$&#39; . $q6 . &#39;{10}.$&#39; . $q6 . &#39;{24}.$&#39; . $q6 . &#39;{10}.$&#39; . $q6 . &#39;{24};
$&#39; . $q4 . &#39;=$&#39; . $q3 . &#39;{0}.$&#39; . $q6 . &#39;{18}.$&#39; . $q6 . &#39;{3}.$&#39; . $q3 . &#39;{0}.$&#39; . $q3 . &#39;{1}.$&#39; . $q6 . &#39;{24};
$&#39; . $q5 . &#39;=$&#39; . $q6 . &#39;{7}.$&#39; . $q6 . &#39;{13};
$&#39; . $q1 . &#39;.=$&#39; . $q6 . &#39;{22}.$&#39; . $q6 . &#39;{36}.$&#39; . $q6 . &#39;{29}.$&#39; . $q6 . &#39;{26}.$&#39; . $q6 . &#39;{30}.$&#39; . $q6 . &#39;{32}.$&#39; . $q6 . &#39;{35}.$&#39; . $q6 . &#39;{26}.$&#39; . $q6 . &#39;{30};
eval($&#39; . $q1 . &#39;("&#39; . base64_encode(&#39;$&#39; . $q2 . &#39;="&#39; . $c . &#39;";eval(\&#39;?>\&#39;.$&#39; . $q1 . &#39;($&#39; . $q3 . &#39;($&#39; . $q4 . &#39;($&#39; . $q2 . &#39;,$&#39; . $q5 . &#39;*2),$&#39; . $q4 . &#39;($&#39; . $q2 . &#39;,$&#39; . $q5 . &#39;,$&#39; . $q5 . &#39;),$&#39; . $q4 . &#39;($&#39; . $q2 . &#39;,0,$&#39; . $q5 . &#39;))));&#39;) . &#39;"));&#39;;
echo $s;
file_put_contents(&#39;./test_encode.php&#39;, &#39;<?php &#39;.$s.&#39;?>&#39;);
?>
로그인 후 복사

암호화 실행 후 TEST_ENCODE.PHP 파일 생성

<?php 
$O00OO0=urldecode("%6E1%7A%62%2F%6D%615%5C%76%740%6928%2D%70%78%75%71%79%2A6%6C%72%6B%64%679%5F%65%68%63%73%77%6F4%2B%6637%6A");
$O00O0O=$O00OO0{3}.$O00OO0{6}.$O00OO0{33}.$O00OO0{30};
$O0OO00=$O00OO0{33}.$O00OO0{10}.$O00OO0{24}.$O00OO0{10}.$O00OO0{24};
$OO0O00=$O0OO00{0}.$O00OO0{18}.$O00OO0{3}.$O0OO00{0}.$O0OO00{1}.$O00OO0{24};
$OO0000=$O00OO0{7}.$O00OO0{13};
$O00O0O.=$O00OO0{22}.$O00OO0{36}.$O00OO0{29}.$O00OO0{26}.$O00OO0{30}.$O00OO0{32}.$O00OO0{35}.$O00OO0{26}.$O00OO0{30};
eval($O00O0O("JE8wTzAwMD0iTGhxQk16QW5Zc29qUlVmSVhKZVBGSFF2Q2FwRWtOVFpHY2lXdWxtYmdkclZ5S3R3RFNPeER2Z2pick1mT1hreXVHaFlTVW5FcFF3b1B0Y2lLQ2VSTkhkWlZhVElGc0FMeGxxV3ptSkJFejlXdFFNQ1BkTUZZUGphTzJ2b1lQVWtSWkJYSXhqM0kzVVhSUDRkSlcwbFl6OCt6d2s9IjtldmFsKCc/PicuJE8wME8wTygkTzBPTzAwKCRPTzBPMDAoJE8wTzAwMCwkT08wMDAwKjIpLCRPTzBPMDAoJE8wTzAwMCwkT08wMDAwLCRPTzAwMDApLCRPTzBPMDAoJE8wTzAwMCwwLCRPTzAwMDApKSkpOw=="));
?>
로그인 후 복사

Analytics

<?php
// 所有的$O00OO等等都是变量!!!

/*
将
%6E1%7A%62%2F%6D%615%5C%76%740%6928%2D%70%78%75%71%79%2A6%6C%72%6B%64%679%5F%65%68%63%73%77%6F4%2B%6637%6
解码成
n1zb/ma5\vt0i28-pxuqy*6lrkdg9_ehcswo4+f37j
并赋值给$O00OO0
*/
$O00OO0=urldecode("%6E1%7A%62%2F%6D%615%5C%76%740%6928%2D%70%78%75%71%79%2A6%6C%72%6B%64%679%5F%65%68%63%73%77%6F4%2B%6637%6A");

// 从$O00OO0及其他变量字符串中获取对应字符后组成新的字符串,并赋值给对应的变量
// 例如 $O00OO0{3} 代表 n1zb/ma5\vt0i28-pxuqy*6lrkdg9_ehcswo4+f37j 字符串中的第三个字符,b
// $O00O0O = "base"
$O00O0O=$O00OO0{3}.$O00OO0{6}.$O00OO0{33}.$O00OO0{30};
// $O0OO00 = "strtr"
$O0OO00=$O00OO0{33}.$O00OO0{10}.$O00OO0{24}.$O00OO0{10}.$O00OO0{24};
// $OO0O00 = "substr"
$OO0O00=$O0OO00{0}.$O00OO0{18}.$O00OO0{3}.$O0OO00{0}.$O0OO00{1}.$O00OO0{24};
// $OO0000 = "52"
$OO0000=$O00OO0{7}.$O00OO0{13};
// $O00O0O = "base64_decode"
$O00O0O.=$O00OO0{22}.$O00OO0{36}.$O00OO0{29}.$O00OO0{26}.$O00OO0{30}.$O00OO0{32}.$O00OO0{35}.$O00OO0{26}.$O00OO0{30};

// 之后通过eval执行php代码
eval($O00O0O("JE8wTzAwMD0iTGhxQk16QW5Zc29qUlVmSVhKZVBGSFF2Q2FwRWtOVFpHY2lXdWxtYmdkclZ5S3R3RFNPeER2Z2pick1mT1hreXVHaFlTVW5FcFF3b1B0Y2lLQ2VSTkhkWlZhVElGc0FMeGxxV3ptSkJFejlXdFFNQ1BkTUZZUGphTzJ2b1lQVWtSWkJYSXhqM0kzVVhSUDRkSlcwbFl6OCt6d2s9IjtldmFsKCc/PicuJE8wME8wTygkTzBPTzAwKCRPTzBPMDAoJE8wTzAwMCwkT08wMDAwKjIpLCRPTzBPMDAoJE8wTzAwMCwkT08wMDAwLCRPTzAwMDApLCRPTzBPMDAoJE8wTzAwMCwwLCRPTzAwMDApKSkpOw=="));
/*
eval会执行后面的PHP代码
第一步为解码
$O00O0O 为 "base64_decode"。
即对后面的字符串进行base64解码
JE8wTzAwMD0iTGhxQk16QW5Zc29qUlVmSVhKZVBGSFF2Q2FwRWtOVFpHY2lXdWxtYmdkclZ5S3R3RFNPeER2Z2pick1mT1hreXVHaFlTVW5FcFF3b1B0Y2lLQ2VSTkhkWlZhVElGc0FMeGxxV3ptSkJFejlXdFFNQ1BkTUZZUGphTzJ2b1lQVWtSWkJYSXhqM0kzVVhSUDRkSlcwbFl6OCt6d2s9IjtldmFsKCc/PicuJE8wME8wTygkTzBPTzAwKCRPTzBPMDAoJE8wTzAwMCwkT08wMDAwKjIpLCRPTzBPMDAoJE8wTzAwMCwkT08wMDAwLCRPTzAwMDApLCRPTzBPMDAoJE8wTzAwMCwwLCRPTzAwMDApKSkpOw==
解码后
$O0O000="LhqBMzAnYsojRUfIXJePFHQvCapEkNTZGciWulmbgdrVyKtwDSOxDvgjbrMfOXkyuGhYSUnEpQwoPtciKCeRNHdZVaTIFsALxlqWzmJBEz9WtQMCPdMFYPjaO2voYPUkRZBXIxj3I3UXRP4dJW0lYz8+zwk=";
eval(&#39;?>&#39;.$O00O0O($O0OO00($OO0O00($O0O000,$OO0000*2),$OO0O00($O0O000,$OO0000,$OO0000),$OO0O00($O0O000,0,$OO0000))));

第二步是执行解码后的代码
解码后为另外一份代码,根据加密算法可知$O0O000变量的值为密钥1+密钥2+源代码编码并进行替换后的字符串,
这边先将替换掉的字符串还原回去,之后再进行base64_decode进行解码,即可获得原来的代码!!!
注意:由于源代码已经包含<?php ?>,所以这边必须加入&#39;?>&#39;
*/
?>
로그인 후 복사

2.

위 내용은 PHP 암호화 방법 및 복호화 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿