Questions tagged [cryptostream]

83 questions
2
votes
1 answer

Does disposing a CryptoStream flush the final block?

From the Microsoft .NET API the following information can be extracted: using will call the implementation of IDisposable.Dispose(); IDisposable.Dispose() should call Flush() on any Stream instance; CryptoStream.Close() will call…
Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263
2
votes
1 answer

The best overload for 'CryptoStream' does not have a parameter named 'leaveOpen'

There is an variable named leaveOpen in cryptostream which is available in **windows ** but not in xamarin. If true then stream won't be close automatically. return new CryptoStream( stream: FileStream, transform: AES.CreateDecryptor(), …
Sorry IwontTell
  • 466
  • 10
  • 29
2
votes
0 answers

Array bounds error with CryptoStream.Read

I have a server/client system, which encrypts images on the server (python) and decrypts them on the client (c#). The cryptography part is working perfectly, except for trying to decrypt info which is several-blocks long (for example, an image, and…
prodev1
  • 53
  • 7
2
votes
3 answers

C# "Bad Data" exception when decrypting encrypted file

Hey I'm very new to encryption and decryption, or even the c# language to be honest. Basically, I have a tcp chat server that "saves" logs and encrypts the text file. This is how I encrypt (based from the MSDN sample): public static void…
Raphael
  • 562
  • 2
  • 9
  • 21
2
votes
1 answer

C# PasswordDeriveBytes: seems that Salt does'nt matter

probably I misunderstood something. The following code produces two equal keys by CryptDeriveKey with two different salt. That is the console result: salt1: 21 3e 18 a3 9a 8b 5f --> Key da 89 ea 3d 91 08 20 98 20 e9 dc 45 d5 97 10 7f 8f 4a 52 15 26…
korowjew
  • 31
  • 5
2
votes
1 answer

How can i add a progress bar on a cryptostream write operation in c#

I have been working on a program to encrypt and decrypt a file as part of a project. The program is working fine on its own but when I try to add a progress bar to it to show the progress of the encryption/decryption process things go wrong. The…
Aman
  • 21
  • 4
2
votes
1 answer

FlushFinalBlock closing application

I'm using CryptoStream for decrypting encrypted text in my app. But when I get to the point of either flushing the final block from the stream or closing it (which should do the same), the app closes. There is no error message, nothing. Even in…
Lisa
  • 157
  • 7
2
votes
3 answers

Encrypted NetworkStream hangs on ReadLine()

I'm learning how to encrypt network streams with the simple example below. Without encryption this example worked fine, but now I've added CryptoStreams the server hangs on "var data = reader.ReadLine()" after the client has written it's message and…
mistakenot
  • 554
  • 3
  • 14
2
votes
1 answer

Issue deserializing encrypted data using BinaryFormatter

Here is my code: public static void Save(T toSerialize, string fileSpec) { BinaryFormatter formatter = new BinaryFormatter(); DESCryptoServiceProvider des = new DESCryptoServiceProvider(); using (FileStream stream =…
2
votes
1 answer

DeflateStream / GZipStream to CryptoStream and vice versa

I want to to compress and encrypt a file in one go by using this simple code: public void compress(FileInfo fi, Byte[] pKey, Byte[] pIV) { // Get the stream of the source file. using (FileStream inFile = fi.OpenRead()) { …
PePe
  • 65
  • 1
  • 6
1
vote
1 answer

Truncating a stream of unknown length x bytes from the end? (.NET)

I need to read a stream of unknown length, excluding the last 20 bytes (hash data). The setup is roughly: Source Stream (with SHA1 hash last 20 bytes) -> SHA1 Hasher Stream (compute on-the-fly and compare with embedded stream hash when stream ends)…
Satellite
  • 531
  • 1
  • 8
  • 16
1
vote
0 answers

CryptoStream - Read vs Write - Is there any difference?

Is there any change in the code needed between if we use CryptoStream with CryptoStreamMode.Read or with CryptoStreamMode.Write ? (Besides reading from it and writing to an outStream or reading from an inStream and writing to the CryptoStream, of…
ispiro
  • 26,556
  • 38
  • 136
  • 291
1
vote
1 answer

Returning Stream via File() causes future operations to throw "the process cannot access the file path because it is being used by another process"

To decrease memory usage when returning a file to a client, whilst decrypting, we have gone with streams. This was working fine until one quirk which is that when you upload the same file back to the server (e.g. when a client modifies it). It…
UncountedBrute
  • 484
  • 1
  • 7
  • 25
1
vote
0 answers

How to use CryptoStream with Span/ReadOnlySpan?

Most of the exemples use MemoryStream with CryptoStream to encrypt/decrypt with RijndaelManaged so I simplified it as much as I could and ended up with the following function to decrypt a buffer. RijndaelManaged csp; //is initialized wih CBC/256bit…
Lizi
  • 153
  • 1
  • 9
1
vote
1 answer

Converting a CryptoStream to using declaration makes memory stream empty when text less than 15 chars

I am having a strange issue when encrypting a text with C#. ReSharper (and I agree) recommends to replace the using block on this code: public object GetEncryptedOrDefault(object value, ICryptoTransform encryptor) { if (encryptor is null) { …
diegosasw
  • 13,734
  • 16
  • 95
  • 159