密码加密解密自定义方法
加密方法:
function lock_url(
t
x
t
,
txt,
txt,key=‘str’){
$txt =
t
x
t
.
txt.
txt.key;
$chars = “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=+”;
$nh = rand(0,64);
$ch =
c
h
a
r
s
[
chars[
chars[nh];
m
d
K
e
y
=
m
d
5
(
mdKey = md5(
mdKey=md5(key.$ch);
m
d
K
e
y
=
s
u
b
s
t
r
(
mdKey = substr(
mdKey=substr(mdKey,$nh%8, $nh%8+7);
t
x
t
=
b
a
s
e
6
4
e
n
c
o
d
e
(
txt = base64_encode(
txt=base64encode(txt);
$tmp = ‘’;
i
=
0
;
i=0;
i=0;j=0;
k
=
0
;
f
o
r
(
k = 0; for (
k=0;for(i=0;
i
<
s
t
r
l
e
n
(
i<strlen(
i<strlen(txt); $i++) {
$k =
k
=
=
s
t
r
l
e
n
(
k == strlen(
k==strlen(mdKey) ? 0 : $k;
j
=
(
j = (
j=(nh+strpos(
c
h
a
r
s
,
chars,
chars,txt[
i
]
)
+
o
r
d
(
i])+ord(
i])+ord(mdKey[$k++]))%64;
$tmp .=
c
h
a
r
s
[
chars[
chars[j];
}
return urlencode(base64_encode(
c
h
.
ch.
ch.tmp));
}
解密方法:
function unlock_url(
t
x
t
,
txt,
txt,key=‘str’){
t
x
t
=
b
a
s
e
6
4
d
e
c
o
d
e
(
u
r
l
d
e
c
o
d
e
(
txt = base64_decode(urldecode(
txt=base64decode(urldecode(txt));
$chars = “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=+”;
$ch = $txt[0];
n
h
=
s
t
r
p
o
s
(
nh = strpos(
nh=strpos(chars,$ch);
m
d
K
e
y
=
m
d
5
(
mdKey = md5(
mdKey=md5(key.$ch);
m
d
K
e
y
=
s
u
b
s
t
r
(
mdKey = substr(
mdKey=substr(mdKey,$nh%8, $nh%8+7);
t
x
t
=
s
u
b
s
t
r
(
txt = substr(
txt=substr(txt,1);
$tmp = ‘’;
i
=
0
;
i=0;
i=0;j=0;
k
=
0
;
f
o
r
(
k = 0; for (
k=0;for(i=0;
i
<
s
t
r
l
e
n
(
i<strlen(
i<strlen(txt); $i++) {
$k =
k
=
=
s
t
r
l
e
n
(
k == strlen(
k==strlen(mdKey) ? 0 : $k;
j
=
s
t
r
p
o
s
(
j = strpos(
j=strpos(chars,
t
x
t
[
txt[
txt[i])-
n
h
−
o
r
d
(
nh - ord(
nh−ord(mdKey[
k
+
+
]
)
;
w
h
i
l
e
(
k++]); while (
k++]);while(j<0) $j+=64;
$tmp .=
c
h
a
r
s
[
chars[
chars[j];
}
return trim(base64_decode(
t
m
p
)
,
tmp),
tmp),key);
}
放入公共文件,直接调用即可。
在网上查找的代码,分享一下。