Questions tagged [cryptostream]
83 questions
1
vote
2 answers
How the MemoryStream declared in outer using statement is still available after inner using statement closes?
The Microsoft docs have the following piece of code on this page:
https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.cryptostream?view=netframework-4.7
The most inner 'using' statement suppose to Dispose csEncrypt, which in…

Tiger Galo
- 289
- 4
- 15
1
vote
0 answers
How to throw while using a CryptoStream without causing a CryptoGraphicException
I'm reading an encrypted file and want to throw a specific error whenever the password is incorrect. Since decrypting with an incorrect password would simply succeed but return gibberish data, I'd like to determine if the password is correct.
The…

RobIII
- 8,488
- 2
- 43
- 93
1
vote
2 answers
Why can't I combine encryption with file storage, when they work individually?
Why can't I combine encryption with file storage, when they work individually?
I'm writing some object properties to a file. First I convert properties to byte array and then I put the whole array (for "one object") together and encrypt it via…

Ben
- 2,435
- 6
- 43
- 57
1
vote
1 answer
The behavior of virtual property in C#
I have next code:
FileStream fs = new FileStream("test.crp",FileMode.Create);
Aes aes = Aes.Create();
FileStream fsKeys = new FileStream("keys.key",FileMode.Open);
fsKeys.Read(aes.IV,0,16);
fsKeys.Read(aes.Key,0,32);
fsKeys.Close();
And the problem…

Rassul Yunussov
- 35
- 1
- 4
1
vote
0 answers
C# CryptoStream FlushFinalBlock System.OutOfMemoryException
UPDATE
I want to encrypt a big file (more than 180 mo for example). But I got a System.OutOfMemoryException with FlushFinalBlock().
It seems to be a valuable methods cause It "finish" encrypting my data with aditionnal bytes at the header and the…

Safe
- 313
- 3
- 13
1
vote
1 answer
Encode CryptoStream to Base64 String in Chunks in C#
There is a method (Version1) that encodes an input stream and there is a function Decrypt() that successfully decodes encoded data. But when the input data is large there could be an error OutOfMemory (on the line "string textEncrypted =…

Evgeny Masloboyschikov
- 11
- 1
- 2
1
vote
1 answer
Using CryptoStream with StreamContent c#
I would like to to read an image from file or blob storage and base64 encode it as a stream and then pass that stream to StreamContent. The following code times out:
[HttpGet, Route("{id}", Name = "GetImage")]
public HttpResponseMessage…

relaxDude
- 101
- 5
1
vote
1 answer
CryptoStream ReportProgress ProgressBar C#
So I am trying to encrypt some files and it works fine, but when I try to include a progress bar to show how far along big files are, like a 100mb-1gb file, the performance is slashed and is very slow. I am assuming its because ReportProgress was…

jLynx
- 1,111
- 3
- 20
- 36
1
vote
1 answer
Largest reliable buffer size than can be used for encryption with cryptostream?
I want to use this encryption method in my project. However, according to the example it reads, encrypts and then writes one byte at a time, which seems inefficient. From looking at the CryptoStream class there are methods to read and write buffers…

Foxman
- 189
- 13
1
vote
1 answer
How to get .NET CryptoStream to read last block
I have a client/server setup with CryptoStream around TcpClient's NetWorkStream on both ends. Communication works great biderectionally when I read from the NetworkStream directly but with CryptoStream I can't read a single block of available data.…

snort
- 2,285
- 3
- 19
- 21
1
vote
2 answers
Base64 - CryptoStream with StreamWriter vs Convert.ToBase64String()
Following feedback from Alexei, a simplification of the question:
How do I use a buffered Stream approach to convert the contents of a CryptoStream (using ToBase64Transform) into a StreamWriter (Unicode encoding) without using…

toadflakz
- 7,764
- 1
- 27
- 40
1
vote
0 answers
CryptoStream does not decrypt properly
I have a working TCP-connection between a server application and a client, wich communicate encrypted with AES. it works with an CryptoStream having an RijndaelManaged En/Decrypter. well Right now, if i want to send sth. like this:…

EaranMaleasi
- 895
- 1
- 13
- 32
1
vote
2 answers
Two CryptoStreams associated with one file in C#
I would like to create a file "myFile" that encrypts the first part using a certain key, and the last part using a certain key. So far I have something like this:
cs1 = new CryptoStream(myFile, symmetricKey1.CreateEncryptor(key1, key1IV),…

Leboff
- 35
- 4
1
vote
0 answers
If i stop CryptoStream Read i get Bad Data exception
I'm having problem with CryptoStream Decryptor.
I'm decrypting file on another Thread.
So here is the problem:
When I let the file to decrypt to the end, everything is allright but when I stop thread, using global variable, and get out of while loop…

Optimus Prime
- 51
- 3
1
vote
4 answers
Wrong size of the encrypted data (AES)
I need to perform encryption array of byte []. I used the example available on the Microsoft. Unfortunately, the encrypted data is truncated to the size that is a multiple of 16. If, in the example of the data I will add 8 times byte 0, the data…

Emil J
- 215
- 2
- 4
- 20