ASP字符串的加密解密函數(shù)
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
rsa.asp[br]<%[br]rem 在asp中實(shí)現(xiàn)加密與解密,加密方法:根據(jù)rsa[br]rem 聯(lián)系:hnsoso@sina.com[br]class clsrsa[br][br]public privatekey[br]public publickey[br]public modulus[br][br]public function crypt(plngmessage, plngkey)[br]on error resume next[br]dim llngmod[br]dim llngresult[br]dim llngindex[br]if plngkey mod 2 = 0 then[br]llngresult = 1[br]for llngindex = 1 to plngkey / 2[br]llngmod = (plngmessage ^ 2) mod modulus[br]' mod may error on key generation[br]llngresult = (llngmod * llngresult) mod modulus [br]if err then exit function[br]next[br]else[br]llngresult = plngmessage[br]for llngindex = 1 to plngkey / 2[br]llngmod = (plngmessage ^ 2) mod modulus[br]on error resume next[br]' mod may error on key generation[br]llngresult = (llngmod * llngresult) mod modulus[br]if err then exit function[br]next[br]end if[br]crypt = llngresult[br]end function[br][br]public function encode(byval pstrmessage)[br]dim llngindex[br]dim llngmaxindex[br]dim lbytascii[br]dim llngencrypted[br]llngmaxindex = len(pstrmessage)[br]if llngmaxindex = 0 then exit function[br]for llngindex = 1 to llngmaxindex[br]lbytascii = asc(mid(pstrmessage, llngindex, 1))[br]llngencrypted = crypt(lbytascii, publickey)[br]encode = encode & numbertohex(llngencrypted, 4)[br]next[br]end function[br][br]public function decode(byval pstrmessage)[br]dim lbytascii[br]dim llngindex[br]dim llngmaxindex[br]dim llngencrypteddata[br]decode = ""[br]llngmaxindex = len(pstrmessage)[br]for llngindex = 1 to llngmaxindex step 4[br]llngencrypteddata = hextonumber(mid(pstrmessage, llngindex, 4))[br]lbytascii = crypt(llngencrypteddata, privatekey)[br]decode = decode & chr(lbytascii)[br]next[br]end function[br][br]private function numbertohex(byref plngnumber, byref plnglength)[br]numbertohex = right(string(plnglength, "0") & hex(plngnumber), plnglength)[br]end function[br][br]private function hextonumber(byref pstrhex)[br]hextonumber = clng("&h" & pstrhex)[br]end function[br][br]end class[br]%>[br][br]test.asp[br][br]<%[br]function encryptstr(message)[br]dim lngkeye[br]dim lngkeyd[br]dim lngkeyn[br]dim strmessage[br]dim objrsa[br][br]lngkeye = "32823"[br]lngkeyd = "20643"[br]lngkeyn = "29893"[br]strmessage = message[br][br]set objrsa = new clsrsa [br][br]objrsa.publickey = lngkeye[br]objrsa.modulus = lngkeyn[br]encryptstr = objrsa.encode(strmessage)[br]set objrsa = nothing[br]end function[br][br]function decryptstr(message)[br]dim lngkeye[br]dim lngkeyd[br]dim lngkeyn[br]dim strmessage[br]dim objrsa[br][br][br]lngkeye = "32823"[br]lngkeyd = "20643"[br]lngkeyn = "29893"[br]strmessage = message[br][br]set objrsa = new clsrsa[br][br]objrsa.privatekey =lngkeyd[br]objrsa.modulus=lngkeyn[br]decryptstr=objrsa.decode(strmessage)[br]set objrsa = nothing[br]end function[br][br]dim last,first[br]first="sohu"[br]response.write "加密前為:"&first[br]last=encryptstr(first)[br]response.write "加密后為"&last[br]response.write "解密后為" &decryptstr(last)[br]%>
該文章在 2010/5/8 15:22:36 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |