当前位置:K88软件开发文章中心编程语言AspAsp01 → 文章内容

Asp对字符串进行加密和解密代码

减小字体 增大字体 作者:佚名     来源:asp编程网  发布时间:2018-12-30 8:32:56

使用md5加密的缺点是不能进行解密,这是一个麻烦事。
现在我想实现的功能是:
给某网站一个地址,这个地址用来展示该网站在公司网站上发布的产品。如果直接使用http://www.aspprogram.cn/a.asp?id=2来的话,客户如果修改2为3后,这个客户就转为其他网站的客户了,那这个网站损失了一个客户,自己的宣传就白宣传了。
所以我想起来对这个2进行加密,以至于客户不可以修改为3。
在网上找了两天,终于找到。
<
%
 
dim 
 
sBASE_64_CHARACTERS,varchar,varasc 
 

 
dim 
 
len1 
 

 
dim 
 

 

 
dim 
 
m3 
 

 
 
 

 
sBASE_64_CHARACTERS 
 

 
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" 
 
 
 

 
sBASE_64_CHARACTERS 
 

 
strUnicode2Ansi(sBASE_64_CHARACTERS) 
 

 
 
 

 
Function strUnicodeLen(asContents) 
 

 
'计算unicode字符串的Ansi编码的长度 
 

 
asContents1="a"&
asContents 
 

 
len1=len(asContents1) 
 

 
k=0 
 

 
for 
 
i=1 
 
to 
 
len1 
 

 
asc1=asc(mid(asContents1,i,1)) 
 

 
if 
 
asc1<

 
then 
 
asc1=65536+asc1 
 

 
if 
 
asc1>
255 
 
then 
 

 
k=k+2 
 

 
else 
 

 
k=k+1 
 

 
end 
 
if 
 

 
next 
 

 
strUnicodeLen=k-1 
 

 
End 
 
Function 
 

 
 
 

 
Function 
strUnicode2Ansi(asContents) 
 

 
'将Unicode编码的字符串,转换成Ansi编码的字符串 
 

 
strUnicode2Ansi="" 
 

 
len1=len(asContents) 
 

 
for 
 
i=1 
 
to 
 
len1 
 

 
varchar=mid(asContents,i,1) 
 

 
varasc=asc(varchar) 
 

 
if 
 
varasc<

 
then 
 
varasc=varasc+65536 
 

 
if 
 
varasc>
255 
 
then 
 

 
varHex=Hex(varasc) 
 

 
varlow=left(varHex,2) 
 

 
varhigh=right(varHex,2) 
 

 
strUnicode2Ansi=strUnicode2Ansi 
 
&
 
 
chrb("&
H" 
 
&
 
 
varlow 
 

 
&
 
 
chrb("&
H" 
 
&
 
 
varhigh 
 

 

 
else 
 

 
strUnicode2Ansi=strUnicode2Ansi 
 
&
 
 
chrb(varasc) 
 

 
end 
 
if 
 

 
next 
 

 
End 
 
function 
 

 
 
 

 
Function 
 
strAnsi2Unicode(asContents) 
 

 
'将Ansi编码的字符串,转换成Unicode编码的字符串 
 

 
strAnsi2Unicode 
 

 
"" 
 

 
len1=lenb(asContents) 
 

 
if 
 
len1=0 
 
then 
 
exit 
 
function 
 

 
for 
 
i=1 
 
to 
 
len1 
 

 
varchar=midb(asContents,i,1) 
 

 
varasc=ascb(varchar) 
 

 
if 
 
varasc 
 
>
 
 
127 
 
then 
 
 
 

 
strAnsi2Unicode 
 

 
strAnsi2Unicode 
 
&
 
 
chr(ascw(midb(asContents,i+1,1) 
 
&
 
 
varchar)) 
 

 
i=i+1 
 

 
else 
 

 
strAnsi2Unicode 
 

 
strAnsi2Unicode 
 
&
 
 
chr(varasc) 
 

 
end 
 
if 
 

 
next 
 

 
End 
 
function 
 

 
 
 

 
Function 
 
Base64encode(asContents) 
 
 
 

 
'将Ansi编码的字符串进行Base64编码 
 

 
'asContents应当是ANSI编码的字符串(二进制的字符串也可以) 
 

 
Dim 
 
lnPosition 
 
 
 

 
Dim 
 
lsResult 
 
 
 

 
Dim 
 
Char1 
 
 
 

 
Dim 
 
Char2 
 
 
 

 
Dim 
 
Char3 
 
 
 

 
Dim 
 
Char4 
 
 
 

 
Dim 
 
Byte1 
 
 
 

 
Dim 
 
Byte2 
 
 
 

 
Dim 
 
Byte3 
 
 
 

 
Dim 
 
SaveBits1 
 
 
 

 
Dim 
 
SaveBits2 
 
 
 

 
Dim 
 
lsGroupBinary 
 
 
 

 
Dim 
 
lsGroup64 
 
 
 

 
Dim 
 
m4,len1,len2 
 

 
 
 

 
len1=Lenb(asContents) 
 

 
if 
 
len1<

 
then 
 
 
 

 
Base64encode="" 
 

 
exit 
 
Function 
 

 
end 
 
if 
 

 
 
 

 
m3=Len1 
 
Mod 
 

 
 
 

 
If 
 
M3 
 
>
 
 

 
Then 
 
asContents 
 

 
asContents 
 
&
 
 
String(3-M3, 
 
chrb(0)) 
 
 
 

 
 
 

 
IF 
 
m3 
 
>
 
 

 
THEN 
 
 
 

 
len1=len1+(3-m3) 
 

 
len2=len1-3 
 

 
else 
 

 
len2=len1 
 

[1] [2] [3] [4]  下一页


Asp对字符串进行加密和解密代码