Closed JKamsker closed 2 years ago
Tagging subscribers to this area: @dotnet/area-system-security, @vcsjones See info in area-owners.md if you want to be subscribed.
Author: | JKamsker |
---|---|
Assignees: | - |
Labels: | `area-System.Security` |
Milestone: | - |
This is the documented change in https://docs.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/6.0/partial-byte-reads-in-streams.
byte[] decrypted = new byte[textBytes.Length]; cs.Read(decrypted, 0, textBytes.Length); result = decrypted;
As documented in the article, Read
is not guaranteed to fill the entire buffer, so Read
should be called in a loop until it indicates there is no more content. The article includes sample code on how to do so.
Alternatively, for .NET 6, you can use the new [EncryptCbc
](https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.symmetricalgorithm.encryptcbc?view=net-6.0#system-security-cryptography-symmetricalgorithm-encryptcbc(system-byte()-system-byte()-system-security-cryptography-paddingmode)) and DecryptCbc
one shots to avoid using CryptoStream
entirely.
Closing as a duplicate of https://github.com/dotnet/runtime/issues/55527.
Description
A program running in .net48 will produce a different output compared to running in net6.
Reproduction Steps
Program.cs:
csproj:
Switch between net48 and net60 and the program will output either "Ok: True" or "Ok: False"
Expected behavior
Both runtimes producing the exact same result.
Actual behavior
While net48 produces the correct value, the value from net6 will be missing exactly 12 characters ("HGXxizO3cOtI")
Regression?
No response
Known Workarounds
Use net4.8
or use a MemoryStream + cs.CopyTo in the Decryption method.
Configuration
No response
Other information
No response