|
-
Jul 5th, 2007, 02:19 PM
#1
Thread Starter
Frenzied Member
RC4 Encryption + File Upload
Ok, I'm giving up.
I am encrypting every data on my website before saving it to a MS Access database. The encryption used is RC4 and I found the script on the net.
Everything works fine, the problem is when I'm saving a file in an OLE Object field, what I'm doing it converting the binary data to text, then I encrypt it and then I re-convert to binary. When I want to get it back, I convert it to text, decrypt it and putting it back to binary and then present it to the browser.
The problem is that it's not 100% accurate and I'm pretty sure it has to do with some chartype. What's even worst is that it works perfectly on my local development server, but when I put it live on the production server, on the web, it stops working.
I have a feeling that the problem lies in the binary to string and string to binary, not so the encrypting part.
Here's the code/functions used:
Code:
'Data manipulation before saving it
binData = uploadRequest("doc").BinaryData
binData = RSBinaryToString(binData)
binData = dataEncrypt(binData)
binData = StringToBinary(binData, cCharSet)
'Data manipulation before downloading it
BinaryData = RSBinaryToString(BinaryData)
BinaryData = dataDecrypt(BinaryData)
BinaryData = StringToBinary(BinaryData, cCharSet)
'Functions
Function StringToBinary(Text, CharSet)
Const adTypeText = 2
Const adTypeBinary = 1
'Create Stream object
Dim BinaryStream 'As New Stream
Set BinaryStream = CreateObject("ADODB.Stream")
'Specify stream type - we want To save text/string data.
BinaryStream.Type = adTypeText
'Specify charset For the source text (unicode) data.
If Len(CharSet) > 0 Then
BinaryStream.CharSet = CharSet
Else
BinaryStream.CharSet = "us-ascii"
End If
'Open the stream And write text/string data To the object
BinaryStream.Open
BinaryStream.WriteText Text
'Change stream type To binary
BinaryStream.Position = 0
BinaryStream.Type = adTypeBinary
'Ignore first two bytes - sign of
BinaryStream.Position = 0
'Open the stream And get binary data from the object
StringToBinary = BinaryStream.Read
End Function
Function MultiByteToBinary(MultiByte)
Dim RS, LMultiByte, Binary
Const adLongVarBinary = 205
Set RS = CreateObject("ADODB.Recordset")
LMultiByte = LenB(MultiByte)
If LMultiByte>0 Then
RS.Fields.Append "mBinary", adLongVarBinary, LMultiByte
RS.Open
RS.AddNew
RS("mBinary").AppendChunk MultiByte & ChrB(0)
RS.Update
Binary = RS("mBinary").GetChunk(LMultiByte)
End If
MultiByteToBinary = Binary
End Function
Function RSBinaryToString(xBinary)
Dim Binary
'MultiByte data must be converted To VT_UI1 | VT_ARRAY first.
If vartype(xBinary)=8 Then Binary = MultiByteToBinary(xBinary) Else Binary = xBinary
Dim RS, LBinary
Const adLongVarChar = 201
Set RS = CreateObject("ADODB.Recordset")
LBinary = LenB(Binary)
If LBinary>0 Then
RS.Fields.Append "mBinary", adLongVarChar, LBinary
RS.Open
RS.AddNew
RS("mBinary").AppendChunk Binary
RS.Update
RSBinaryToString = RS("mBinary")
Else
RSBinaryToString = ""
End If
End Function
Thanks a lot, hopefully someone has an idea...
The only thing I can see why it's working a server and not another, might be the access database driver?? I will go check that right now.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|