Broken Link
Broken Link

Reputation: 2406

Simple encrypt/decrypt functions in Classic ASP

Are there any simple encrypt/decrypt functions in Classic ASP?

The data that needs to be encrypted and decrypted is not super sensitive. So simple functions would do.

Upvotes: 4

Views: 35413

Answers (3)

Daniel Rodriguez
Daniel Rodriguez

Reputation: 61

I know is a bit late for BrokenLink, but for the record and others like me who were looking for the same.

I found this https://www.example-code.com/vbscript/crypt_aes_encrypt_file.asp.

It needs to install a chilkat ActiveX component on WindowsServer. But this inconvenient becomes convenient when looking resources and processing time.

Its very easy to use, and the given example is pretty clear. To make it your own, just change the "keyHex" variable value and voilá.

Upvotes: 0

Oratius
Oratius

Reputation: 9

Try this:

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

'********* set a random string with random length ***********
cryptkey = "GNQ?4i0-*\CldnU+[vrF1j1PcWeJfVv4QGBurFK6}*l[H1S:oY\v@U?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*YoAlkBK@`3A)trZsO5xv@5@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

Upvotes: 0

Tomalak
Tomalak

Reputation: 338326

4guysfromrolla.com: RC4 Encryption Using ASP & VBScript

See the attachments at the end of the page.

The page layout looks a bit broken to me, but all the info is there. I made it readable it by deleting the code block from the DOM via bowser development tools.

Upvotes: 4

Related Questions