paip.跨平台跨語言自訂加密方法_PHP教程

來源:互聯網
上載者:User
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加密。。可是...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.