ASP字符串的加密解密函数
当前位置:点晴教程→知识管理交流
→『 技术文档交流 』
rsa.asp[br]<%[br]rem 在asp中实现加密与解密,加密方法:根据rsa[br]rem 联系: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 编辑过 |
关键字查询
相关文章
正在查询... |