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 www.2cto.com
newchar=chr( charInt-ascw(keyarr(i)))
newstr=newstr+newchar
next
newstr=back_str(newstr)
atiDecode=newstr
end function
作者:attilax
http://www.bkjia.com/PHPjc/478092.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/478092.htmlTechArticlepaip.跨平台跨語言自訂加密方法 今天主要是要在ASP和PHP系統模組間進行參數傳遞,為了方便,不用MD5簽名,直接準備使用 DES加密。。可是...