By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,911 Members | 1,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,911 IT Pros & Developers. It's quick & easy.

Can cookie store non-ascii?

P: n/a
Hi - I'm doing simple XOR encryption on a password before storing it in a
cookie. I use the same 2-way encryption/decryption routine at each end
(before writing/after reading). Something is getting screwed up because this
doesn't work as expected. Can cookies store any non-ascii characters? (I'm
thinking that maybe this limitation is what is screwing me up). Thanks,

(I've confirmed that the 2-way encryption using the following routine does
work correctly)

Paul.

-----------
Private Function cryptUserDetails(ByVal strTemp As String) As String
'Encrypts or decrypts a string. This encryption is a simple XOR based on
'a random seed number. Passing the encrypted string will decrypt it, passing
'the unencrypted string will decrypt it. Returns a blank string on error.
'Instring= the string to work with
'KeyValue=the seed value (MUST BE POSITIVE)
Dim X As Integer
Dim KeyValue As Integer
Dim singlechar As String
Dim charnum As Integer
Dim randomint As Integer
Dim OutString As String
Dim i As Integer, Seed As Single

On Error GoTo EncryptError
KeyValue = 133 'Len(strTemp) * 13 'psw addition
OutString = ""
Seed = Rnd(-KeyValue)
For i = 1 To Len(strTemp)
singlechar = Mid$(strTemp, i, 1)
charnum = Asc(singlechar)
randomint = CInt(256 * Rnd())
charnum = charnum Xor randomint
singlechar = Chr(charnum)
OutString = OutString + singlechar
Next i
cryptUserDetails = OutString
Exit Function
EncryptError:
'Encryption error; return a blank string
cryptUserDetails = ""
Exit Function
End Function
Nov 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I would recommend encoding the binary data using something like base64.

"Paul W" <qq*@qqq.com> wrote in message
news:#Y*************@TK2MSFTNGP12.phx.gbl...
Hi - I'm doing simple XOR encryption on a password before storing it in a
cookie. I use the same 2-way encryption/decryption routine at each end
(before writing/after reading). Something is getting screwed up because this doesn't work as expected. Can cookies store any non-ascii characters? (I'm
thinking that maybe this limitation is what is screwing me up). Thanks,

(I've confirmed that the 2-way encryption using the following routine does
work correctly)

Paul.

-----------
Private Function cryptUserDetails(ByVal strTemp As String) As String
'Encrypts or decrypts a string. This encryption is a simple XOR based on
'a random seed number. Passing the encrypted string will decrypt it, passing 'the unencrypted string will decrypt it. Returns a blank string on error.
'Instring= the string to work with
'KeyValue=the seed value (MUST BE POSITIVE)
Dim X As Integer
Dim KeyValue As Integer
Dim singlechar As String
Dim charnum As Integer
Dim randomint As Integer
Dim OutString As String
Dim i As Integer, Seed As Single

On Error GoTo EncryptError
KeyValue = 133 'Len(strTemp) * 13 'psw addition
OutString = ""
Seed = Rnd(-KeyValue)
For i = 1 To Len(strTemp)
singlechar = Mid$(strTemp, i, 1)
charnum = Asc(singlechar)
randomint = CInt(256 * Rnd())
charnum = charnum Xor randomint
singlechar = Chr(charnum)
OutString = OutString + singlechar
Next i
cryptUserDetails = OutString
Exit Function
EncryptError:
'Encryption error; return a blank string
cryptUserDetails = ""
Exit Function
End Function

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.