简体   繁体   中英

Classic ASP Cookie Authentication Code Not Working

I've received the cookie authentication code below from one of my vendors.

Supposedly is this classic ASP code but when I plug it into my classic asp program, it crashes with a 500 server error.

Is the code below truly classic asp? Can anyone tell me why this code does not work in classic asp?

Thank you!

Sal

=========================

Function DeCrypt(ByVal strEncrypted As String, ByVal strKey As String) As String 
    ' cookie data is stored urlencoded and must be decoded before processing
    strEncrypted = HttpUtility.UrlDecode(strEncrypted)

    Dim iKeyChar As String
    Dim iStringChar As String
    Dim iDeCryptChar As String
    Dim strDecrypted As String = String.Empty

    For i As Integer = 0 To strEncrypted.Length - 1
        iKeyChar = Asc(strKey(i)).ToString()
        iStringChar = Asc(strEncrypted(i)).ToString()
        iDeCryptChar = iKeyChar Xor iStringChar
        strDecrypted &= Chr(iDeCryptChar)
    Next

    Return strDecrypted
End Function

no, it looks like vb.net code. it's easy enough to convert over:

Function DeCrypt(strEncrypted, strKey) ' cookie data is stored urlencoded and must be decoded before processing 

strEncrypted = URLDecode(strEncrypted)
Dim iKeyChar
Dim iStringChar
Dim iDeCryptChar
Dim strDecrypted
Dim i

For i = 0 To strEncrypted.Length - 1
    iKeyChar = CStr(Asc(strKey(i)))
    iStringChar = CStr(Asc(strEncrypted(i)))
    iDeCryptChar = iKeyChar Xor iStringChar
    strDecrypted = strDecrypted & Chr(iDeCryptChar)
Next

URLDecode = strDecrypted
End Function

FUNCTION URLDecode(str)
'// This function:
'// - decodes any utf-8 encoded characters into unicode characters eg. (%C3%A5 = å)
'// - replaces any plus sign separators with a space character
'//
'// IMPORTANT:
'// Your webpage must use the UTF-8 character set. Easiest method is to use this META tag:
'// <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
'//
    Dim objScript
    Set objScript = Server.CreateObject("ScriptControl")
    objScript.Language = "JavaScript"
    URLDecode = objScript.Eval("decodeURIComponent(""" & str & """.replace(/\+/g,"" ""))")
    Set objScript = NOTHING
END FUNCTION

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM