Can't decrypt encrypted file (Error: Lenght of the encrypted data is invalid)


Can't decrypt encrypted file (Error: Lenght of the encrypted data is...
Author
Message
dgsoft
dgsoft
StrataFrame User (135 reputation)StrataFrame User (135 reputation)StrataFrame User (135 reputation)StrataFrame User (135 reputation)StrataFrame User (135 reputation)StrataFrame User (135 reputation)StrataFrame User (135 reputation)StrataFrame User (135 reputation)StrataFrame User (135 reputation)
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



GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
dgsoft - 14 Years Ago
Greg McGuffey - 14 Years Ago
dgsoft - 14 Years Ago
Greg McGuffey - 14 Years Ago
dgsoft - 14 Years Ago
dgsoft - 14 Years Ago
                         Ok.
Now problem is fixed.
I choose wrong datatype for SQL...
dgsoft - 14 Years Ago
                             Glad you got it working!
Greg McGuffey - 14 Years Ago
                         Hi Denis. I have created a sample following Greg's code and it works...
Ivan George Borges - 14 Years Ago
                             Hi Ivan,
Yes.. my main mistake was using wrong type.....
dgsoft - 14 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search