Group: StrataFrame Users
Posts: 93,
Visits: 236
|
Hi,
I try to encrypt and store files in SQL Server database [binarydata] VarChar(MAX) field..
Problem is.. I can't DECRYPT already ecnrypted file.. (with strings I have no problem)
1) Way to encrypt and SaveFile in the Database
Dim loEncrypt As MicroFour.StrataFrame.Security.Encryption.TripleDESWrapper = New MicroFour.StrataFrame.Security.Encryption.TripleDESWrapper
loEncrypt.EncryptFile(lcFilename)
Dim lcSQLExpr = String.Format("UPDATE [ErpData].[dbo].[KONTAKTE_DOKUMENTE] SET [BinaryData] = (SELECT BulkColumn FROM OPENROWSET(BULK '{0}', SINGLE_BLOB) AS InsertData) WHERE PK_ID = {1}", lcFilename, tnDocumentId)
If Me.ExecuteNonQuery(lcSQLExpr) > 0 Then
File.Delete(lcFilename)
End If
==== On this step I encrypt the file and save data into binarydata field
2) I try to restore and decrypt file
' Here is "ME" is businessObject.
Dim fs As FileStream = New FileStream(lcFilename, FileMode.CreateNew, FileAccess.Write)
Dim bw As BinaryWriter = New BinaryWriter(fs)
bw.Write(Me.binarydata, 0, Me.binarydata.Length)
bw.Flush()
bw.Close()
fs.Close()
Dim loEncrypt As MicroFour.StrataFrame.Security.Encryption.TripleDESWrapper = New MicroFour.StrataFrame.Security.Encryption.TripleDESWrapper
Try
loEncrypt.DecryptFile(lcFilename)
lcReturn = lcFilename
Catch ex As Exception
MicroFour.StrataFrame.Messaging.MessageForm.ShowMessage(ex.Message)
End Try
=======! HERE I'V GOT AN EXCEPTION "The length of the encrypted is invalid"
I expect something wrong with BinaryWriter.. but what?
Thanks
Denis
|