2014-01-21 114 views
2

有沒有辦法讓這個工作在ASP頁面? 它與charset windows-1253工作正常,但現在我必須將我的網站 轉換爲UTF-8,我唯一的問題是加密和解密。我有加密會員註冊密碼,現在用UTF-8,解密後的密碼看起來像這樣:2��8��6RC4加密和UTF-8 ASP解密經典

請給我一些幫助(對不起,我的英語)。 這是RC4代碼:

Dim sbox(255) 
    Dim rc4Key(255) 

    Sub RC4Initialize(strPwd) 

     dim tempSwap, a, b  

     intLength = len(strPwd) 

     for a = 0 To 255 

     rc4Key(a) = asc(mid(strpwd, (a mod intLength)+1, 1)) 

     sbox(a) = a      
     next 

     b = 0 

     for a = 0 To 255 
     b = (b + sbox(a) + rc4Key(a)) Mod 256   
     tempSwap = sbox(a) 
     sbox(a) = sbox(b) 
     sbox(b) = tempSwap 
     Next 

    End Sub 

    function EnDeCrypt(plaintxt, psw)  

     dim temp, a, i, j, k, cipherby, cipher  

     i = 0 
     j = 0 

     RC4Initialize psw 

     for a = 1 To Len(plaintxt) 
     i = (i + 1) Mod 256 
     j = (j + sbox(i)) Mod 256 
     temp = sbox(i) 
     sbox(i)= sbox(j) 
     sbox(j)= temp 

     k = sbox((sbox(i) + sbox(j)) Mod 256) 

     cipherby = Asc(Mid(plaintxt, a, 1)) Xor k 
     cipher  = cipher & Chr(cipherby)   
     next 

     enDeCrypt = cipher    

    end function 

    function RC4EnCryptASC(plaintxt, psw)  

     dim temp, a, i, j, k, cipherby, cipher  

     i = 0 
     j = 0 

     RC4Initialize psw 

     for a = 1 To Len(plaintxt) 
     i = (i + 1) Mod 256 
     j = (j + sbox(i)) Mod 256 
     temp = sbox(i) 
     sbox(i)= sbox(j) 
     sbox(j)= temp 

     k  = sbox((sbox(i) + sbox(j)) Mod 256) 

     cipherby = Asc(Mid(plaintxt, a, 1)) Xor k   
     cipher  = cipher & "|"& cipherby   
     next    

     RC4EnCryptASC = cipher    

    end function 

    function RC4DeCryptASC(plaintxt, psw)  

     plaintxt = transformToCHR(plaintxt) 

     dim temp, a, i, j, k, cipherby, cipher  

     i = 0 
     j = 0  

     dim arrayEncrypted    

     RC4Initialize psw   

     for a = 1 To Len(plaintxt) 
     i = (i + 1) Mod 256 
     j = (j + sbox(i)) Mod 256 
     temp = sbox(i) 
     sbox(i)= sbox(j) 
     sbox(j)= temp 

     k = sbox((sbox(i) + sbox(j)) Mod 256) 

     cipherby = Asc(Mid(plaintxt, a, 1)) Xor k 
     cipher  = cipher & Chr(cipherby)   
     next 

     RC4DeCryptASC = cipher      

    end function 

function transformToCHR(plaintxt) 


     dim returnText, arrayEncrypted 
     arrayEncrypted = split(plaintxt, "|")    

     returnText=""    

     for a = 1 to ubound(arrayEncrypted)   
     returnText=returnText&CHR(arrayEncrypted(a))   
     next    

     transformToCHR = returnText 
end function 

回答

1

我認爲你必須使用ASCW函數和等效等功能處理Unicode字符?

+0

好的,但Unicode代碼點將不同於Windows-1253(擴展ISO-8859-1拉丁)點的值。 –

+0

我將使用此腳本和Windows-1253解密密碼,然後將其存儲在數據庫中而不加密。然後我會將網站轉爲UTF-8,然後使用由AscW函數編輯的腳本進行加密。但我該如何在腳本中添加AscW函數? – WebStyler

+0

@WebStyler ascw等等都是建立在vbscript函數中的 – ulluoink

1

好吧,終於我做到了。 我只是將每個asc換成ascW ,每個chr都換成chrW,它的工作原理非常完美。