2010-08-09 81 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