473,320 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Help with CryptoStream and incomplete files...

Ok, with the help of some examples found on the web and some minor
modifications on our own, we have a simple and working encrypt and
decrypt solution. It runs as a service, watches for files with a
specific extension in a specific directory. The files are uploaded by
FTP to this directory. The service then does the following steps:

1) Verify it can open the file (so we know it's fully uploaded).
2) Try to decrypt the file with known keys
3) DRM the file
4) Move the file to an another directory for download at a later time.
This works great. As long as the file gets completely uploaded. If
the file is a partial file, the CryptoStream we have open to the file
dies out at near the end of the file with the following error
(gathered from our logfile):

------
Length of the data to decrypt is invalid. | TransformFinalBlock |
System.Security.Cryptography.CryptographicExceptio n: Length of the
data to decrypt is invalid.
at
System.Security.Cryptography.CryptoAPITransform.Tr ansformFinalBlock(Byte[]
inputBuffer, Int32 inputOffset, Int32 inputCount)
at System.Security.Cryptography.CryptoStream.FlushFin alBlock()
at System.Security.Cryptography.CryptoStream.Close()
------

What I'd like to be able to do is to delete that file either before
the CryptoStream is used if there is some way to tell it's an
incomplete file or to delete the file once I get the above exception.
The problem is, I can't access the file. I've tried
CryptoStream.Close, CryptoStream.Clear, etc, nothing gets me access to
that file again until the service is stopped.

I've included some code below, which is a partial code listing along
with lots of calls to UpdateStatus (which is just updated a log file
with the time and the message) as I was trying to track down this
problem.

Any help anyone could offer would be GREAT.

Thanks much,

M

This a portion of the main function that runs when a file is found in
the directory:

----------------------------------
Private Function ProcessFile(ByVal file_name As String) As Boolean
Dim tempPath As String
Dim tempName As String
Dim testStream As FileStream

'Update Status
UpdateStatus("Processing: " & file_name)

'Try opening if the file, if it fails, start the timer.
Try
testStream = New FileStream(file_name, FileMode.Open,
FileAccess.Read)
testStream.Close()
Catch ex As System.IO.IOException
UpdateStatus("Unable to Open File: (expected error): " &
ex.Message)
timeRetry.Enabled = True
Return False
Catch ex As Exception
UpdateStatus("Unexpected Error Occured: " & ex.Message)
timeRetry.Enabled = True
Return False
End Try

'Decrypt File
UpdateStatus("Decrypting: " & file_name)
tempPath = file_name.Substring(0, file_name.LastIndexOf("."))
& ".wmv"
tempName = tempPath.Substring(tempPath.LastIndexOf("\") + 1,
tempPath.Length - (tempPath.LastIndexOf("\") + 1))
Try
CryptFile(m_Password, file_name, tempPath, False)
Catch ex As Exception
UpdateStatus("Decrypting Error: " & ex.Message & " | " &
ex.TargetSite().Name & " | " & ex.ToString)
'If we can't encode the file, it's no good to us and we
delete it.
Try
UpdateStatus("Decrypting Error: REMOVING INVALID
FILE!")
If Not crypto_stream Is Nothing Then
UpdateStatus("MANUALLY DOING MY THING!")
crypto_stream.Close()
crypto_stream = Nothing
End If
System.IO.File.Delete(file_name)
System.IO.File.Delete(tempPath)
Catch ex1 As Exception
UpdateStatus("Decrypt clean up error: " & ex1.Message)
End Try
Return True
End Try
[DRM AND TEMP FILE DELETE HAPPENS AFTER HERE]
---------------------------------------------------------------------

This is the cryptfile function:
(in this code, crypto_stream is defined as a global, so I could get
access to the handle back in the main function, just as another shot
at closing is properly... it's defined as "private crypto_stream as
CryptoStream"
------------------------------------------------
Private Sub CryptFile(ByVal password As String, ByVal in_file As
String, ByVal out_file As String, ByVal encrypt As Boolean)
' Create input and output file streams.
Dim in_stream As FileStream
Dim out_stream As FileStream
Dim des_provider As New TripleDESCryptoServiceProvider
Dim block_size_bits As Integer
Dim key As Byte() = Nothing
Dim iv As Byte() = Nothing
Dim crypto_transform As ICryptoTransform
Const BLOCK_SIZE As Integer = 1024
Dim buffer(BLOCK_SIZE) As Byte
Dim bytes_read As Integer
UpdateStatus("CRYPTFILE!")
Try
in_stream = New FileStream(in_file, FileMode.Open,
FileAccess.Read)
out_stream = New FileStream(out_file, FileMode.Create,
FileAccess.Write)
Catch ex As Exception
UpdateStatus("First CLOSING")
If Not in_stream Is Nothing Then
in_stream.Close()
in_stream = Nothing
End If
If Not out_stream Is Nothing Then
out_stream.Close()
out_stream = Nothing
End If
Throw ex
End Try

' Encrypt or decrypt the file.
Try
' Find a valid key size for this provider.
Dim key_size_bits As Integer = 0
For i As Integer = 1024 To 1 Step -1
If des_provider.ValidKeySize(i) Then
key_size_bits = i
Exit For
End If
Next i
UpdateStatus("Key Size: " & key_size_bits)
Debug.Assert(key_size_bits > 0)

' Get the block size for this provider.
UpdateStatus("Block Size: " & block_size_bits)
block_size_bits = des_provider.BlockSize

' Generate the key and initialization vector.
UpdateStatus("Make Key and IV!")
MakeKeyAndIV(password, key_size_bits, block_size_bits,
key, iv)

UpdateStatus("Setting to Decrypt")
' Make the encryptor or decryptor.
If encrypt Then
crypto_transform = des_provider.CreateEncryptor(key,
iv)
Else
crypto_transform = des_provider.CreateDecryptor(key,
iv)
End If

' Attach a crypto stream to the output stream.
UpdateStatus("Attaching the crypto stream")
crypto_stream = New CryptoStream(out_stream,
crypto_transform, CryptoStreamMode.Write)

UpdateStatus("At the Do loop")
Do
Try
' Read some bytes.
UpdateStatus("Read Some Bytes")
bytes_read = in_stream.Read(buffer, 0, BLOCK_SIZE)
If bytes_read = 0 Then
UpdateStatus("Read 0 Bytes")
If Not crypto_stream Is Nothing Then
crypto_stream.Close()
crypto_stream = Nothing
End If
If Not in_stream Is Nothing Then
in_stream.Close()
in_stream = Nothing
End If
If Not out_stream Is Nothing Then
out_stream.Close()
out_stream = Nothing
End If
Exit Do
End If

' Write the bytes into the CryptoStream.
UpdateStatus("Encrypting " & bytes_read & "
bytes")
crypto_stream.Write(buffer, 0, bytes_read)
Catch ex As Exception
' Close the streams.
UpdateStatus("Second CLOSING")
If Not crypto_stream Is Nothing Then
crypto_stream.Close()
crypto_stream = Nothing
End If
If Not in_stream Is Nothing Then
in_stream.Close()
in_stream = Nothing
End If
If Not out_stream Is Nothing Then
out_stream.Close()
out_stream = Nothing
End If

Throw ex
End Try
Loop
Catch ex As Exception
' Close the streams.
UpdateStatus("Third CLOSING")
If Not crypto_stream Is Nothing Then
crypto_stream.Close()
crypto_stream = Nothing
End If
If Not in_stream Is Nothing Then
in_stream.Close()
in_stream = Nothing
End If
If Not out_stream Is Nothing Then
out_stream.Close()
out_stream = Nothing
End If

Throw ex
End Try

' Close the streams.
UpdateStatus("Last CLOSING")
crypto_stream.Close()
in_stream.Close()
out_stream.Close()
End Sub
-------------------------------------------
Log file of what happens to file:
------------------------------
[6/9/2005 8:04:31 AM] Starting
[6/9/2005 8:04:32 AM] Processing:
C:\Inetpub\wwwroot\Vivid\video\33291394.xxx
[6/9/2005 8:04:32 AM] Decrypting:
C:\Inetpub\wwwroot\Vivid\video\33291394.xxx
[6/9/2005 8:04:32 AM] CRYPTFILE!
[6/9/2005 8:04:32 AM] Key Size: 192
[6/9/2005 8:04:32 AM] Block Size: 0
[6/9/2005 8:04:32 AM] Make Key and IV!
[6/9/2005 8:04:33 AM] Setting to Decrypt
[6/9/2005 8:04:33 AM] Attaching the crypto stream
[6/9/2005 8:04:33 AM] At the Do loop
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 1024 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Encrypting 651 bytes
[6/9/2005 8:04:33 AM] Read Some Bytes
[6/9/2005 8:04:33 AM] Read 0 Bytes
[6/9/2005 8:04:33 AM] Second CLOSING
[6/9/2005 8:04:33 AM] Third CLOSING
[6/9/2005 8:04:34 AM] Decrypting Error: Length of the data to decrypt
is invalid. | TransformFinalBlock |
System.Security.Cryptography.CryptographicExceptio n: Length of the
data to decrypt is invalid.
at
System.Security.Cryptography.CryptoAPITransform.Tr ansformFinalBlock(Byte[]
inputBuffer, Int32 inputOffset, Int32 inputCount)
at System.Security.Cryptography.CryptoStream.FlushFin alBlock()
at System.Security.Cryptography.CryptoStream.Close()
at FreeAndClear.FreeAndClear.CryptFile(String password, String
in_file, String out_file, Boolean encrypt)
at FreeAndClear.FreeAndClear.ProcessFile(String file_name)
[6/9/2005 8:04:34 AM] Decrypting Error: REMOVING INVALID FILE!
[6/9/2005 8:04:34 AM] MANUALLY DOING MY THING!
[6/9/2005 8:04:34 AM] Decrypt clean up error: Length of the data to
decrypt is invalid.
--------------------------------------------------------------------------------
Jul 21 '05 #1
8 2967
MattP <ma***@interviewusa.com> wrote:
Ok, with the help of some examples found on the web and some minor
modifications on our own, we have a simple and working encrypt and
decrypt solution. It runs as a service, watches for files with a
specific extension in a specific directory. The files are uploaded by
FTP to this directory. The service then does the following steps:
<snip>
I've included some code below, which is a partial code listing along
with lots of calls to UpdateStatus (which is just updated a log file
with the time and the message) as I was trying to track down this
problem.

Any help anyone could offer would be GREAT.


Rather than manually catching the exception and closing, use a
try/finally block, one for each stream (this would be easy to do in C#,
or the next version of VB.NET - slightly harder here). That way you'll
make sure that you close each of the streams. As it is, I suspect
you're only closing the cryptostream (and failing to do that, due to
the exception) each time.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
In the log file, it shows each one getting called. Including the
global one I made for CryptoStream. The close seems to go through,
though it doesn't work, apparently.

And Finally does exist in VB.net... I'll go ahead and move things
around just to see if finally does something different for us.

Thanks much,

M

On Thu, 9 Jun 2005 20:16:33 +0100, Jon Skeet [C# MVP]
<sk***@pobox.com> wrote:
MattP <ma***@interviewusa.com> wrote:
Ok, with the help of some examples found on the web and some minor
modifications on our own, we have a simple and working encrypt and
decrypt solution. It runs as a service, watches for files with a
specific extension in a specific directory. The files are uploaded by
FTP to this directory. The service then does the following steps:


<snip>
I've included some code below, which is a partial code listing along
with lots of calls to UpdateStatus (which is just updated a log file
with the time and the message) as I was trying to track down this
problem.

Any help anyone could offer would be GREAT.


Rather than manually catching the exception and closing, use a
try/finally block, one for each stream (this would be easy to do in C#,
or the next version of VB.NET - slightly harder here). That way you'll
make sure that you close each of the streams. As it is, I suspect
you're only closing the cryptostream (and failing to do that, due to
the exception) each time.


Jul 21 '05 #3
MattP <ma***@interviewusa.com> wrote:
In the log file, it shows each one getting called. Including the
global one I made for CryptoStream. The close seems to go through,
though it doesn't work, apparently.
It shows CryptoStream.Close being called, but not Close on the other
streams. That's the problem, I believe. I believe CryptoStream.Close is
throwing an exception each time, stopping the other Closes from being
called.
And Finally does exist in VB.net...


Yes, but the Using statement which would make it much easier doesn't.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #4
Jon, you correct, it's throwing this exception when I try to close the
cryptostream:

Value cannot be null.
Parameter name: inputBuffer | TransformFinalBlock |
System.ArgumentNullException: Value cannot be null.
Parameter name: inputBuffer

I have no idea to get around that.

M

On Thu, 9 Jun 2005 20:41:58 +0100, Jon Skeet [C# MVP]
<sk***@pobox.com> wrote:
MattP <ma***@interviewusa.com> wrote:
In the log file, it shows each one getting called. Including the
global one I made for CryptoStream. The close seems to go through,
though it doesn't work, apparently.


It shows CryptoStream.Close being called, but not Close on the other
streams. That's the problem, I believe. I believe CryptoStream.Close is
throwing an exception each time, stopping the other Closes from being
called.
And Finally does exist in VB.net...


Yes, but the Using statement which would make it much easier doesn't.


Jul 21 '05 #5
MattP <ma***@interviewusa.com> wrote:
Jon, you correct, it's throwing this exception when I try to close the
cryptostream:

Value cannot be null.
Parameter name: inputBuffer | TransformFinalBlock |
System.ArgumentNullException: Value cannot be null.
Parameter name: inputBuffer

I have no idea to get around that.


Well, that's probably when you try to close it the second time. Just
try to close it once, but make sure you close *all* the streams. That's
where Try/Finally comes in - have three nested Try blocks, each with a
Finally block that closes one of the streams.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #6
I'll give that a try... but shouldn't checking to see if the object
is nothing work after I've set it to nothing?

M

On Thu, 9 Jun 2005 21:32:28 +0100, Jon Skeet [C# MVP]
<sk***@pobox.com> wrote:
MattP <ma***@interviewusa.com> wrote:
Jon, you correct, it's throwing this exception when I try to close the
cryptostream:

Value cannot be null.
Parameter name: inputBuffer | TransformFinalBlock |
System.ArgumentNullException: Value cannot be null.
Parameter name: inputBuffer

I have no idea to get around that.


Well, that's probably when you try to close it the second time. Just
try to close it once, but make sure you close *all* the streams. That's
where Try/Finally comes in - have three nested Try blocks, each with a
Finally block that closes one of the streams.


Jul 21 '05 #7
MattP <ma***@interviewusa.com> wrote:
I'll give that a try... but shouldn't checking to see if the object
is nothing work after I've set it to nothing?


No, because you're not getting as far as setting the variable to
nothing (note the terminology here - you can't set an object to
nothing, it doesn't make sense as a concept). The CryptoStream.Close
call is throwing the exception, so you're getting out to the next catch
block.

(It's very rarely worth setting things to null/Nothing explicitly in my
experience, by the way. It just makes the code harder to read.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #8
Jon,

You are the winner! It was doing exactly as you thought and I just
wasn't following it correctly. Got it fixed and all is well now.

Thanks a lot of the help.

As for setting "variables" to nothing, I agree completely, I was just
getting desperate. :D

M

On Thu, 9 Jun 2005 21:43:40 +0100, Jon Skeet [C# MVP]
<sk***@pobox.com> wrote:
MattP <ma***@interviewusa.com> wrote:
I'll give that a try... but shouldn't checking to see if the object
is nothing work after I've set it to nothing?


No, because you're not getting as far as setting the variable to
nothing (note the terminology here - you can't set an object to
nothing, it doesn't make sense as a concept). The CryptoStream.Close
call is throwing the exception, so you're getting out to the next catch
block.

(It's very rarely worth setting things to null/Nothing explicitly in my
experience, by the way. It just makes the code harder to read.)


Jul 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: weixiang | last post by:
Hi, I want to use DES and CryptoStream to serialize a encrypted stream to a file with a header "CRYPT". And I wrote these code: To store: FileStream fileStream = new FileStream(fileName,...
1
by: Saper\(ek\) | last post by:
I need to encrypt some data in my program, so I've created 2 functions to encrypt and decrypt data. I've created a simple program to test it, and... it crashes. It wors ok on XP, but on win98 it...
10
by: Alejandro Castañaza | last post by:
Hi. I'm writing a program, and I need to send confidential data through the network, so I decided to use encryption, using the System.Security.Cryptography namespace. I'm using the sockets...
8
by: MattP | last post by:
Ok, with the help of some examples found on the web and some minor modifications on our own, we have a simple and working encrypt and decrypt solution. It runs as a service, watches for files with...
1
by: Simon Whale | last post by:
Hi All, i am using the following two functions to encrypt data, bank details. i can encrypt the details no problems. but when i try to decrypt the details i get the following error "PKCS7...
3
by: pachinco | last post by:
Hello, I am having a problem encrypting a tiff image..it always loses information after i decrypt and I know it has something to do with the encoding but i can't figure it out. Any help would be...
7
by: semedao | last post by:
Hi, I am using cryptostream on both sides on tcp connection that pass data. I am also use asyc socket , so , the data that recieved in the callback method not always have the length of the buffer...
9
by: TC | last post by:
Hey All, I posted this to the Crypto users group and forgot to add the VB.Net users group. I apologize for any confusion. I have been testing a try / catch / finally block and purposely...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.