paip.跨平台跨语言自定义加密方法

paip.跨平台跨语言自定义加密方法

今天主要是要在ASP和PHP系统模块间进行参数传递,为了方便,不用MD5签名,直接准备使用

DES加密。。可是ASP和PHP的DES不能相互加觖密。。。好向还有什么CBC模式,IV向量什么的

。一大堆,调了半天还是不行,算了,还是自己写加密方法吧。。

密码加密主要的方法就是替换,移位。。另外,我的要求是,还需要可以使用密钥,此外还需要算法

简单。。DES算法一看就是一大陀,MD,难用。PASS。。。虽然效果好,有点复杂,不好重写啊

。。

这里,我构思了下加密觖密的思路:

1.先把字符串进行反转
2.把字符串与KEY组进行循环相加
3.相加的结果转为16进制字符连起来。。主要是为了省点空间。。
4.返回结果就可 以了。。。
5.解密的过程反过来就可以了。。

dim key_L71723
 key_L71723="iluvnjyn"
 dim msg
 msg="admin"

dim newstr
newstr=atiEncode(msg,key_L71723) 
 response.Write( newstr)  '显示加密结果是D7D5E2DACF
 response.Write( atiDecode(newstr,key_L71723) )

---------------------------------------------
function atiEncode(msg,key)
  
    msg=back_str(msg)   '反转字符串
 dim  key_L71723
 key_L71723= key
    key_L71723=key_L71723+key_L71723
   key_L71723=key_L71723+key_L71723
    key_L71723=key_L71723+key_L71723    
 dim msgarr
 msgarr=str2array(msg)
 dim keyarr
 keyarr=str2array(key_L71723)
 dim newstr
 newstr=""
 '与KEY组进行循环相加
 for i=0 to ubound(msgarr)
  dim char
         char=msgarr(i)
  dim newchar  'int format
  newchar = asc (char)+asc(keyarr(i))
  newchar= hex(newchar)
  
  newstr=newstr+cstr(newchar)
     next 
  
 atiEncode=newstr
end function

 

function atiDecode(msg,key)
 
 dim  key_L71723
 key_L71723= key
    key_L71723=key_L71723+key_L71723
   key_L71723=key_L71723+key_L71723
    key_L71723=key_L71723+key_L71723    
 dim msgarr
 msgarr=str2arrayx(msg,2)
 dim keyarr
 keyarr=str2array(key_L71723)
 dim newstr
 newstr="" 

 for i=0 to ubound(msgarr)
  dim charInt
 
          charInt=chn10(msgarr(i) )  'encode char
  
  dim newchar
  newchar=chr( charInt-ascw(keyarr(i)))
  newstr=newstr+newchar
     next

   newstr=back_str(newstr) 
 atiDecode=newstr
end function

posted @ 2012-07-18 05:02  attilaxAti  阅读(16)  评论(0编辑  收藏  举报