Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Security > CryptographicException: Length of the data to decrypt is invalid

Reply
Thread Tools

CryptographicException: Length of the data to decrypt is invalid

 
 
Barb
Guest
Posts: n/a
 
      04-11-2006
I've got a decryption function that works on files. It's a .NET COM-enabled
object, and it works most everywhere except on this one server. The strange
part is that when my decryption logic runs, it actually decrypts some of the
file, and then doesn't keep going. I can successfully decrypt the same file
in a different environment with no problems. So, it might decrypt the 1st
half of the first line of the file, and then leave the rest decrypted (and my
original file gets corrupted somehow).

Anyway, I'm hoping somebody can take a look at the following routine that
uses 3Des and see if there's something different I can be doing to make sure
that the encrypted file decrypts properly. I'm thinking that in this
environment, maybe I'm hitting a column delimiter, or some odd character.

Any suggestions are appreciated:

Public Function DecryptFile(ByVal SourcePath As String, ByVal decryptPath As
String) As String
Dim stream1 As FileStream = Nothing
Dim stream2 As FileStream = Nothing
Try
Dim buffer1 As Byte() = New Byte(128 - 1) {}
Dim info1 As New FileInfo(SourcePath)
Dim info2 As New FileInfo(decryptPath)
If info2.Exists Then
info2.Delete()
End If
stream1 = New FileStream(info1.FullName, FileMode.Open)
stream2 = New FileStream(decryptPath, FileMode.CreateNew)
Dim stream3 As New CryptoStream(stream1, Me.des.CreateDecryptor,
CryptoStreamMode.Read)
Dim num1 As Integer = stream3.Read(buffer1, 0, buffer1.Length)
Do While (num1 > 0)
stream2.Write(buffer1, 0, num1)
stream2.Flush()
num1 = stream3.Read(buffer1, 0, buffer1.Length)
Loop
stream2.Close()
stream1.Close()
Catch exception1 As UnauthorizedAccessException
Return ("Make sure the permissions are set correctly for the
user accessing. " & exception1.Message)
Catch exception2 As Exception
Return exception2.ToString
Finally
If (Not stream2 Is Nothing) Then
stream2.Close()
End If
If (Not stream1 Is Nothing) Then
stream1.Close()
End If
End Try
Return "Decrypt Complete"
End Function
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
decrypt challenge - perl encrypt with ruby decrypt aktxyz@gmail.com Ruby 1 06-16-2007 01:30 PM
Length of the data to decrypt is invalid Hannibal111111 ASP .Net 0 06-27-2006 08:42 PM
Length of the data to decrypt is invalid Bishoy George ASP .Net Security 4 04-07-2006 10:22 PM
Forms authentication decrypt invalid data lanegth exception steve baker ASP .Net Security 0 08-03-2005 11:05 AM
Length of data to decrypt is invalid Rijndael hivie ASP .Net Security 2 06-13-2005 07:30 PM



Advertisments