欢迎光临
我们一直在努力

在asp中加密与解密对应的函数-ASP教程,安全加密

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

在asp中加密方法有对应的解密方法好象不多,现在根据前辈资料整理出在asp中加密与解密函数

rsa.asp

<%

rem 在asp中实现加密与解密,加密方法:根据rsa

rem 联系:hnsoso@sina.com

class clsrsa

public privatekey

public publickey

public modulus

public function crypt(plngmessage, plngkey)

on error resume next

dim llngmod

dim llngresult

dim llngindex

if plngkey mod 2 = 0 then

llngresult = 1

for llngindex = 1 to plngkey / 2

llngmod = (plngmessage ^ 2) mod modulus

mod may error on key generation

llngresult = (llngmod * llngresult) mod modulus

if err then exit function

next

else

llngresult = plngmessage

for llngindex = 1 to plngkey / 2

llngmod = (plngmessage ^ 2) mod modulus

on error resume next

mod may error on key generation

llngresult = (llngmod * llngresult) mod modulus

if err then exit function

next

end if

crypt = llngresult

end function

public function encode(byval pstrmessage)

dim llngindex

dim llngmaxindex

dim lbytascii

dim llngencrypted

llngmaxindex = len(pstrmessage)

if llngmaxindex = 0 then exit function

for llngindex = 1 to llngmaxindex

lbytascii = asc(mid(pstrmessage, llngindex, 1))

llngencrypted = crypt(lbytascii, publickey)

encode = encode & numbertohex(llngencrypted, 4)

next

end function

public function decode(byval pstrmessage)

dim lbytascii

dim llngindex

dim llngmaxindex

dim llngencrypteddata

decode = ""

llngmaxindex = len(pstrmessage)

for llngindex = 1 to llngmaxindex step 4

llngencrypteddata = hextonumber(mid(pstrmessage, llngindex, 4))

lbytascii = crypt(llngencrypteddata, privatekey)

decode = decode & chr(lbytascii)

next

end function

private function numbertohex(byref plngnumber, byref plnglength)

numbertohex = right(string(plnglength, "0") & hex(plngnumber), plnglength)

end function

private function hextonumber(byref pstrhex)

hextonumber = clng("&h" & pstrhex)

end function

end class

%>

test.asp

<!–#include file="rsa.asp"–>

<%

function encryptstr(message)

dim lngkeye

dim lngkeyd

dim lngkeyn

dim strmessage

dim objrsa

lngkeye = "32823"

lngkeyd = "20643"

lngkeyn = "29893"

strmessage = message

set objrsa = new clsrsa

objrsa.publickey = lngkeye

objrsa.modulus = lngkeyn

encryptstr = objrsa.encode(strmessage)

set objrsa = nothing

end function

function decryptstr(message)

dim lngkeye

dim lngkeyd

dim lngkeyn

dim strmessage

dim objrsa

lngkeye = "32823"

lngkeyd = "20643"

lngkeyn = "29893"

strmessage = message

set objrsa = new clsrsa

objrsa.privatekey =lngkeyd

objrsa.modulus=lngkeyn

decryptstr=objrsa.decode(strmessage)

set objrsa = nothing

end function

dim last,first

first="sohu"

response.write "加密前为:"&first

last=encryptstr(first)

response.write "加密后为"&last

response.write "解密后为" &decryptstr(last)

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