2010-08-09 88 views

回答

4

4guysfromrolla.com:RC4 Encryption Using ASP & VBScript

見附件頁面的末端。

頁面佈局看起來有點破碎,但所有的信息都在那裏。我通過使用bowser開發工具從DOM中刪除了代碼塊來使它可讀。

+0

我越想過這個問題。我的情況是有點複雜。你能否看到你是否可以回答這個問題? http://stackoverflow.com/questions/3453908/key-management-classic-asp-encrypt-decrypt – 2010-08-10 22:20:29

+0

@Broken鏈接:我不明白爲什麼使用RC4不適合所描述的場景。您需要在兩個ASP頁面(一個通用密碼)之間共享一個祕密,然後您將能夠確定發送到一個頁面的加密消息是否由另一個頁面生成。當然,密碼永遠不會被破壞,這是唯一的解決辦法。 P.S .:我不打算回答另外一個問題,以提高別人試一試的機會。 – Tomalak 2010-08-10 23:15:52

+0

這是我的意圖,當我發佈這個問題。但問題是可以說我正在使用RC4 ..我加密了一些隨機密鑰併發送它,然後當我必須驗證它,RC4將只是解密數據它是,它不會告訴天氣它能夠成功或不能解密。由於我沒有將生成的密鑰存儲在第一位,所以我不知道如果這是我生成或不生成的密鑰。 – 2010-08-10 23:46:18

0

試試這個:

' Encrypt and decrypt functions for classic ASP (by TFI) 

'********* set a random string with random length *********** 
cryptkey = "GNQ?4i0-*\CldnU+[vrF1j1PcWeJfVv4QGBurFK6}*l[H1S:oY\[email protected]?i,oD]f/n8oFk6NesH--^PJeCLdp+(t8SVe:ewY(wR9p-CzG<,Q/(U*.pXDiz/KvnXP`BXnkgfeycb)1A4XKAa-2G}74Z8CqZ*A0P8E[S`6RfLwW+Pc}13U}_y0bfscJ<vkA[JC;0mEEuY4Q,([U*XRR}lYTE7A(O8KiF8>W/m1D*[email protected]`3A)[email protected]@MRRFkt\" 

'**************************** ENCRYPT FUNCTION ****************************** 

'*** Note: bytes 255 and 0 are converted into the same character, in order to 
'*** avoid a char 0 which would terminate the string 

function encrypt(inputstr) 
     Dim i,x 
     outputstr="" 
     cc=0 
     for i=1 to len(inputstr) 
       x=asc(mid(inputstr,i,1)) 
       x=x-48 
       if x<0 then x=x+255 
       x=x+asc(mid(cryptkey,cc+1,1)) 
       if x>255 then x=x-255 
       outputstr=outputstr&chr(x) 
       cc=(cc+1) mod len(cryptkey) 
     next 
     encrypt=server.urlencode(replace(outputstr,"%","%25")) 
end function 

'**************************** DECRYPT FUNCTION ****************************** 

function decrypt(byval inputstr) 
     Dim i,x 
     inputstr=urldecode(inputstr) 
     outputstr="" 
     cc=0 
     for i=1 to len(inputstr) 
       x=asc(mid(inputstr,i,1)) 
       x=x-asc(mid(cryptkey,cc+1,1)) 
       if x<0 then x=x+255 
       x=x+48 
       if x>255 then x=x-255 
       outputstr=outputstr&chr(x) 
       cc=(cc+1) mod len(cryptkey) 
     next 
     decrypt=outputstr 
end function 

'**************************************************************************** 

Function URLDecode(sConvert) 
    Dim aSplit 
    Dim sOutput 
    Dim I 
    If IsNull(sConvert) Then 
     URLDecode = "" 
     Exit Function 
    End If 
    'sOutput = REPLACE(sConvert, "+", " ") ' convert all pluses to spaces 
    sOutput=sConvert 
    aSplit = Split(sOutput, "%") ' next convert %hexdigits to the character 
    If IsArray(aSplit) Then 
     sOutput = aSplit(0) 
     For I = 0 to UBound(aSplit) - 1 
      sOutput = sOutput & Chr("&H" & Left(aSplit(i + 1), 2)) & Right(aSplit(i + 1), Len(aSplit(i + 1)) - 2) 
     Next 
    End If 
    URLDecode = sOutput 
End Function 
+0

我已經測試過這個,但似乎得到了奇怪的結果 - 我加密,然後解密,並與原始密碼進行比較,並與其不一致。幾百個 - 只有少數被成功地解密爲原始形式,許多出來包括有趣的人物,例如:'t2E 6' – kneidels 2013-08-27 01:23:27