Re: Simple file encryption decryption problem in C#

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Thu, 23 Apr 2009 22:37:59 +0100, "Andrew Jocelyn"
<j055@xxxxxxxxxxxxxxxx> wrote:

Hi

I've created an encrypt and decrypt function, modified from article
http://www.dotnetthis.com/Articles/Crypto.htm. It accepts streams instead of
file paths. The functions work if I send in FileStreams. I can encrypt and
decrypt. If I send in a MemoryStream to it then write the stream to the
website response stream the stream seems to be truncated. It needs to work
with all file types. It breaks even with a short text file.
You say that your code works with a FileStream. Display the encrypted
contents of the FileStream and compare them with the encrypted
contents of the MemoryStream, same password, IV and plaintext of
course. TripleDES is a 64 bit (8 byte) block cypher, so if the
MemoryStream cyphertext is 8 bytes shorter then you are probably not
flushing out the last block properly when encoding. If the decoded
plaintext is shorter then you may not be flushing on decode. Padding
may mean that the difference is not exactly 8 bytes on decoding.

Unless you absolutely have to use TripleDES for backwards
compatibility with old code, you should avoid it because it is now
obsolescent and insecure. Use Rijndael (AES) instead.

Code below. What am I doing wrong?
You are posting incomplete and uncompilable code. Post the minimal
code that shows the problem and can be cut and pasted directly into an
IDE and compile first time. Help us to help you.

rossum

[snip code]


Many thanks
Andrew


.



Relevant Pages

  • Re: Video streaming DRM
    ... online mechanisms and/or utilizing revocation. ... The AES key is then used to encrypt the stream in ECB mode. ... PBKDF2 is pointless unless something not described is added. ...
    (sci.crypt)
  • Re: FlushFinalBlock method was called twice on a CryptoStream ERROR MESSAGE
    ... and only requires the one CryptoStream object (one for encrypt and one for ... What I meant before is each 32 bytes string ... > TransformBlock to encrypt but haven't had much success unencrypting on the ... >> of the streamReader/writer to save another stream indirection. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Rijndael Decryption not working
    ... Stream streamToConvert = ConvertStringIntoStream; ... CryptoStream kbsCryptoStream = new CryptoStream(streamToConvert, ... I can encrypt without any problem but while decrypting I got junk. ... Rijndael rijndaelAlgorithm = Rijndael.Create; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: HDTV Connection
    ... |> But what if a plain 8VSB demodulator ... This would make the whole technology of 8VSB unusable for data transmission ... | device is free to encrypt in any way it wants. ... I wouldn't attempt to crack it by decrypting the stream it encrypts. ...
    (alt.tv.tech.hdtv)
  • Re: Crypto API using RC2 instead of RC4?
    ... Matt wrote: ... > The KB article was great, but they don't provide the decrypt function ... > in VB 6, only the encrypt. ... Algorithm or RC4 Stream Algorithm. ...
    (microsoft.public.platformsdk.security)