欢迎光临
我们一直在努力

用asp写一个简单的加密和解密的类。。。。-ASP教程,ASP应用

建站超值云服务器,限时71元/月

class base64class

rem const

dim sbase_64_characters转化码

dim lenstring 计算字符串的长度

dim icount 计数器

dim returnvalue 返回值

dim tempchar缓存字符

dim tempstring缓存字符串

dim paramstring 参数字符串

dim temhex缓存缓存十六进制

dim templow缓存低位

dim temphigh缓存高位

dim mod3string

dim mod4string

dim tempbinary

dim tempbyteone

dim tempbytetwo

dim tempbytethree

dim tempbytefour

dim tempsavebitsone

dim tempsavebitstwo

********************************************

begin初始化类

********************************************

private sub class_initialize()

sbase_64_characters = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/" end sub

********************************************

end初始化类

********************************************

********************************************

begin销毁类

********************************************

private sub class_terminate()

sbase_64_characters="" end sub

********************************************

end销毁类

********************************************

********************************************

begin将ansi编码的字符串进行base64编码

********************************************

public function encode(paramstring)

tempstring=""

returnvalue=""

lenstring=len(paramstring)

if lenstring<1 then

encode=returnvalue

else

mod3string=lenstring mod 3

补足位数是为了便于计算

if mod3string>0 then

lenstring=lenstring+3-mod3string

lenstring=lenstring-3

end if

*************************begin

for icount=1 to lenstring step 3

tempbinary = mid(paramstring, icount, 3)

response.write tempbinary

tempbyteone= asc(mid(tempbinary, 1, 1)): tempsavebitsone = tempbyteone and 3

tempbytetwo = asc(mid(tempbinary, 2, 1)): tempsavebitstwo = tempbytetwo and 15

tempchar = asc(mid(tempbinary, 3, 1))

tempbyteone = mid(sbase_64_characters, ((tempbyteone and 252) \ 4) + 1, 1)

tempbytetwo = mid(sbase_64_characters, (((tempbytetwo and 240) \ 16) or (tempsavebitsone * 16) and &hff) + 1, 1)

tempbytethree = mid(sbase_64_characters, (((tempchar and 192) \ 64) or (tempsavebitstwo * 4) and &hff) + 1, 1)

tempbytefour = mid(sbase_64_characters, (tempchar and 63) + 1, 1)

tempstring = tempbyteone & tempbytetwo & tempbytethree & tempbytefour returnvalue=returnvalue & tempstring next

*************************end

*************************begin处理最后剩余的几个字符

if mod3string>0 then

tempbinary = mid(paramstring, icount, mod3string)

if mod3string=1 then

tempstring = tempbinary & chr(64) & chr(64) & chr(64) 用@号补足位数

else tempstring = tempbinary & chr(64) & chr(64) 用@号补足位数

end if

returnvalue=returnvalue & tempstring

end if

*************************end处理最后剩余的几个字符

encode=returnvalue end if end function

********************************************

end将ansi编码的字符串进行base64编码

********************************************

********************************************

end将base64编码字符串转换成ansi编码的字符串

********************************************

public function decode(paramstring)

tempstring=""

returnvalue=""

lenstring=len(paramstring)

if lenstring<1 then

decode=returnvalue

else

mod4string=lenstring mod 4

if mod4string >0 then 字符串长度应当是4的倍数

decode=returnvalue

else begin判断是不是@号

if mid(paramstring, lenstring-1, 1) = "@" then

mod4string=2

end if

if mid(paramstring, lenstring-2, 1) = "@" then

mod4string=1

end if

end判断是不是@号

if mod4string>0 then

lenstring=lenstring-4

end if

******************************begin

for icount=1 to lenstring step 4

tempstring = mid(paramstring, icount, 4)

tempbyteone = instr(sbase_64_characters, mid(tempstring, 1, 1)) – 1

tempbytetwo = instr(sbase_64_characters, mid(tempstring, 2, 1)) – 1

tempbytethree = instr(sbase_64_characters, mid(tempstring, 3, 1)) – 1

tempbytefour = instr(sbase_64_characters, mid(tempstring, 4, 1)) – 1

tempbyteone = chr(((tempbytetwo and 48) \ 16) or (tempbyteone * 4) and &hff) tempbytetwo = "" & chr(((tempbytethree and 60) \ 4) or (tempbytetwo * 16) and &hff)

tempbytethree = chr((((tempbytethree and 3) * 64) and &hff) or (tempbytefour and 63))

tempstring=tempbyteone & tempbytetwo & tempbytethree

returnvalue=returnvalue & tempstring

next

******************************end

处理最后剩余的几个字符

if mod4string > 0 then

tempstring=left(right(paramstring,4),mod4string)

returnvalue = returnvalue & tempstring

end if

decode=returnvalue

end if

end if

end function

********************************************

end将base64编码字符串转换成ansi编码的字符串

********************************************

end class

在这个类中简单的实现了一个加密和解密。目的是和大家分享一下。这个类的破解非常简单。看看我的注释就知道是怎么回事了。下次编写一个java的加密和解密的类。

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 用asp写一个简单的加密和解密的类。。。。-ASP教程,ASP应用
分享到: 更多 (0)

相关推荐

  • 暂无文章