469,903 Members | 2,201 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

Can cookie store non-ascii?

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
1 1697
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.

Similar topics

9 posts views Thread by Marco Krechting | last post: by
15 posts views Thread by Edwin Knoppert | last post: by
3 posts views Thread by Mike | last post: by
7 posts views Thread by =?Utf-8?B?SlA=?= | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.