Jay_SE
asked on
Encrypt / decrypt querystring and cookie variables?
I am looking for a vb-script function that encrypts and decrypts strings in an easy and efficient way (encryption on page 1 and decryption on page 2), but at the same time it should not make the decoded string too long. I have tried several vb-script encoders/encrypters, but the encoded text is either to similar to the real text or the encoded string becomes very, very long.
Is there someone out there who can provide me with some good code-samples in vb-script that fit the description above?
I want to encrypt 3 things:
1) user id and password that is stored in a client cookie
2) the hidden field values in a form
3) the data in the querystring that is viewed in the client browser.
Especially I want to encrypt the data shown after the questionmark when sending data between two asp-pages.
An example of how it looks now is: "https://www.experts-exchange.com/file.asp?category=1,2,4®istered=1..."
I want this to look like this instead: "https://www.experts-exchange.com/file.asp?7718d2cd0d812337dcd..."
or possibly like this "https://www.experts-exchange.com/file.asp?category=18d2cd0d8®istered=18d2cd0d8..."
..or similar.
Is there someone out there who can provide me with some good code-samples in vb-script that fit the description above?
I want to encrypt 3 things:
1) user id and password that is stored in a client cookie
2) the hidden field values in a form
3) the data in the querystring that is viewed in the client browser.
Especially I want to encrypt the data shown after the questionmark when sending data between two asp-pages.
An example of how it looks now is: "https://www.experts-exchange.com/file.asp?category=1,2,4®istered=1..."
I want this to look like this instead: "https://www.experts-exchange.com/file.asp?7718d2cd0d812337dcd..."
or possibly like this "https://www.experts-exchange.com/file.asp?category=18d2cd0d8®istered=18d2cd0d8..."
..or similar.
ASKER
I will try this solution, but since it is not an encryption-mechanism where I can use any key I am not sure if it fits my perpouse.
Is it possible to use an external key instead of the session id?
Is it possible to use an external key instead of the session id?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Then this is it. Thank you for this help!
Can anybody help? I am using this script successfully until I try to encrypt a string longer than 9 characters, at which point it falls over with the error message below.
How might I solve this?
Thanks
How might I solve this?
Thanks
Microsoft VBScript runtime error '800a0005'
Invalid procedure call or argument: 'Asc'
/crypt.asp, line 9
strSample1 = EnCrypt(rsData("MyDate"))
strSample1 = Decrypt(strSample1)
Cheers,
Scott
'-------------------------
Function EnCrypt(strCryptThis)
Dim strChar, iKeyChar, iStringChar, i,g_Key, varSessionID
varSessionID = Session.SessionID
g_Key = mid(varSessionID,1,Len(str
for i = 1 to Len(strCryptThis)
iKeyChar = Asc(mid(g_Key,i,1))
iStringChar = Asc(mid(strCryptThis,i,1))
iCryptChar = iKeyChar Xor iStringChar
iCryptCharHex = Hex(iCryptChar)
iCryptCharHexStr = cstr(iCryptCharHex)
if len(iCryptCharHexStr)=1 then iCryptCharHexStr = "0" & iCryptCharHexStr
strEncrypted = strEncrypted & iCryptCharHexStr
next
EnCrypt = strEncrypted
End Function
'-------------------------
Function DeCrypt(strEncrypted)
Dim strChar, iKeyChar, iStringChar, i,g_Key, varSessionID
varSessionID = Session.SessionID
g_Key = mid(varSessionID,1,Len(str
for i = 1 to Len(strEncrypted) /2
iKeyChar = (Asc(mid(g_Key,i,1)))
iStringChar2 = mid(strEncrypted,(i*2)-1,2
iStringChar = CLng("&H" & iStringChar2)
iDeCryptChar = iKeyChar Xor iStringChar
strDecrypted = strDecrypted & chr(iDeCryptChar)
next
DeCrypt = strDecrypted
End Function
'-------------------------