Uploading/Downloading Encrypted Files to a Database

A

annemarie

Hello all - I'm having a problem with trying to load some encrypted
binary files into a SQLServer 2000 database. The files are going into
the database, but when I pull them out, they are 1 byte larger (328 ->
329) and when verified our tool says that the file is invlaid cause
it's been modified. I'm not sure if the bit is being added when they
are going in or coming out of the database.

Anyone have some suggestions on what I am doing wrong?
The help is appreciated.

UPLOAD CODE
___________________________________
Dim con As New SqlConnection(CONNECTION)
Dim da As New SqlDataAdapter("Select * from TABLENAME", con)
Dim MyCB As SqlCommandBuilder = New SqlCommandBuilder(da)
Dim ds As New DataSet()

da.MissingSchemaAction = MissingSchemaAction.AddWithKey
con.Open()
da.Fill(ds, "TABLENAME")

Dim fs As New FileStream("D:\SOURCEFILE.enc",
FileMode.OpenOrCreate, FileAccess.Read)

Dim MyData(fs.Length) As Byte
fs.Read(MyData, 0, fs.Length)
fs.Close()
ds.Tables("TABLENAME").Rows(1)("FIELDNAME") = MyData
da.Update(ds, "TABLENAME")
fs = Nothing
MyCB = Nothing
ds = Nothing
da = Nothing

con.Close()
con = Nothing
Response.Write("File saved to database")

======================================================

DOWNLOAD CODE
_________________________

Dim con As New SqlConnection(<CONNECTION>)
Dim da As New SqlDataAdapter("Select * from TABLENAME", con)
Dim MyCB As SqlCommandBuilder = New SqlCommandBuilder(da)
Dim ds As New DataSet()

con.Open()
da.Fill(ds, "TABLENAME")
Dim myRow As DataRow
myRow = ds.Tables("TABLENAME").Rows(1)

Dim MyData() As Byte
MyData = myRow("FIELDNAME")

Response.Buffer = True
response.addHeader("content-disposition",
"attachment;filename=FILENAME.enc")
Response.ContentType = "application/octet-stream"
Response.BinaryWrite(MyData)
MyCB = Nothing
ds = Nothing
da = Nothing
con.Close()
con = Nothing
response.end()

+++++++++++++++++++++++++++++++++++++++
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top