asp如何加密数据 asp文件加密

主机教程 建站分享 2年前 (2022-12-05) 187次浏览

文章摘要:asp如何加密数据 asp文件加密

在asp中使用MD5加密算法对数据进行加密,具体方法如下:

在asp中使用MD5加密算法对数据进行加密,具体方法如下:

<%

Function hmac(data,key)

dim ipad,opad,k_ipad,k_opad,i

for i = 1 to ( 64 - len(key) )

key = key & chr(&H00)

next

'Response.Write(len(key))

ipad = "6666666666666666666666666666666666666666666666666666666666666666"

opad = "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"

k_ipad = strXor(ipad,key ) 'key Xor ipad

k_opad = strXor(opad,key ) 'key Xor opad

hmac =md5( k_opad & pack( md5( k_ipad & data ) ) )

End Function

Function strXor(strdata,strkey)

Dim strChar, iKeyChar, iStringChar, i,iCryptChar

for i = 1 to Len(strdata)

iKeyChar = Asc(mid(strkey,i,1))

iStringChar = Asc(mid(strdata,i,1))

iCryptChar = iKeyChar Xor iStringChar

strXor = strXor & Chr(iCryptChar)

next

End Function

Function ShowHex(data)

dim i

dim ch

l=lenB(data)

for i = 1 to l

ch=midB(data,i,1)

h=trim(hex(ascB(ch)))

if len(h)=1 then

h="0"+h

end if

ShowHex = ShowHex + h+" "

next

end Function

Function strtoHex(achar)

if Asc(achar) < 58 then

strtoHex = Asc(achar) - 48

else

strtoHex = Asc(achar) - 87

end if

End Function

Function pack(amd5)

dim i,n

dim abyte,hsum,lsum

n = len(amd5)/2

for i = 0 to n - 1

hsum = strtoHex(mid(amd5,2*i + 1,1)) * 16 + strtoHex(mid(amd5,2*i + 2,1))

if hsum > 127 and i < n - 1 then

i = i + 1

'Response.write(mid(amd5,2*i + 1,1) & mid(amd5,2*i + 2,1) )

lsum = strtoHex(mid(amd5,2*i + 1,1)) * 16 + strtoHex(mid(amd5,2*i + 2,1))

pack = pack & chr(hsum * 256 + lsum )

else

'Response.write(mid(amd5,2*i + 1,1) & mid(amd5,2*i + 2,1) )

pack = pack & chrw(hsum)

end if

next

End Function

Response.Write(md5(hmac("testdata","029a1228ea025cf897fe305715f3b794")))

%>


声明:
若非注明,本站文章源于互联网收集整理和网友分享发布,如有侵权,请联系站长处理。
文章名称:asp如何加密数据 asp文件加密
文章链接:http://www.7966.org/post/14254.html
转载请注明出处

喜欢 (0)