<%
rem ##############################################
rem 加密解密
rem ##############################################
rem 在asp中實現加密與解密,加密方法:根據rsa
rem 聯絡:[email protected]
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
%>
<%
rem 加密呼叫
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
rem 解密呼叫
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)
對稱加密解密類
using system using system.collections.generic using system.web using system.security.cryptography using system.text using system.io using system.web.u...
加密解密幫助類(對稱加密)
1 對稱加密幫助類 2public static class cryptohelper3 22 provider.key encoding.utf8.getbytes key 2324 encryptor provider.createencryptor 25 建立明文流 26byte clearb...
加密與解密處理類
using system using system.collections.generic using system.linq using system.text using system.io using system.security.cryptography namespace sedo 定義...
加密解密Url的類
string querystringkey abcdefgh url傳輸引數加密key string passwordkey hgfedcba password加密key region 公共方法 加密url傳輸的字串 public string encryptquerystring string q...
C 常見加密解密類
加密方式 加密向量 是否可逆 md5 sha 不需要不可逆 rsa不需要 可逆aes des 需要可逆 md5為不可逆的加密方式一般用作密碼驗證,當密碼加密結果一致時則認為登陸成功 public class md5 public string rsaencrypt string normaltxt ...