动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   Asp → 阅读文章

 一段在asp中加密与解密对应的函数

作者来源: 
阅读 1258 人次 , 2006-4-3 0:03:00 


在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)

%>

 本文Tagsmd5  加密  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:MD5算法研究
· 下一篇:提高ASP性能的最佳选择(一)
· 几个常用的小函数
· ASP程序界面的多语言支持
· 打开页面就是全屏的方法
· 用Visual C#动态生成组件
· 程序调试—发现及处理错误


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077