Skip to content

Commit ea49f32

Browse files
authored
Document breaking change in crypto introduced in 3.0 (#20366)
1 parent 6566ad5 commit ea49f32

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

docs/core/compatibility/2.2-3.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ If you're migrating from version 2.2 to version 3.0 of .NET Core, ASP.NET Core,
324324
- [EnvelopedCms defaults to AES-256 encryption](#envelopedcms-defaults-to-aes-256-encryption)
325325
- [Minimum size for RSAOpenSsl key generation has increased](#minimum-size-for-rsaopenssl-key-generation-has-increased)
326326
- [.NET Core 3.0 prefers OpenSSL 1.1.x to OpenSSL 1.0.x](#net-core-30-prefers-openssl-11x-to-openssl-10x)
327+
- [CryptoStream.Dispose transforms final block only when writing](#cryptostreamdispose-transforms-final-block-only-when-writing)
327328

328329
[!INCLUDE [begin-trusted-cert-linux](~/includes/core-changes/cryptography/3.0/begin-trusted-cert-linux.md)]
329330

@@ -341,6 +342,10 @@ If you're migrating from version 2.2 to version 3.0 of .NET Core, ASP.NET Core,
341342

342343
***
343344

345+
[!INCLUDE [CryptoStream.Dispose transforms final block only when writing](~/includes/core-changes/cryptography/3.0/cryptography-cryptostream-dispose-final-block-write.md)]
346+
347+
***
348+
344349
## Entity Framework Core
345350

346351
[Entity Framework Core breaking changes](/ef/core/what-is-new/ef-core-3.0/breaking-changes)

docs/core/compatibility/2.2-3.1.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ If you're migrating from version 2.2 to version 3.1 of .NET Core, ASP.NET Core,
322322
- [EnvelopedCms defaults to AES-256 encryption](#envelopedcms-defaults-to-aes-256-encryption)
323323
- [Minimum size for RSAOpenSsl key generation has increased](#minimum-size-for-rsaopenssl-key-generation-has-increased)
324324
- [.NET Core 3.0 prefers OpenSSL 1.1.x to OpenSSL 1.0.x](#net-core-30-prefers-openssl-11x-to-openssl-10x)
325+
- [CryptoStream.Dispose transforms final block only when writing](#cryptostreamdispose-transforms-final-block-only-when-writing)
325326

326327
[!INCLUDE [begin-trusted-cert-linux](~/includes/core-changes/cryptography/3.0/begin-trusted-cert-linux.md)]
327328

@@ -339,6 +340,10 @@ If you're migrating from version 2.2 to version 3.1 of .NET Core, ASP.NET Core,
339340

340341
***
341342

343+
[!INCLUDE [CryptoStream.Dispose transforms final block only when writing](~/includes/core-changes/cryptography/3.0/cryptography-cryptostream-dispose-final-block-write.md)]
344+
345+
***
346+
342347
## Entity Framework Core
343348

344349
[Entity Framework Core breaking changes](/ef/core/what-is-new/ef-core-3.0/breaking-changes)

docs/core/compatibility/cryptography.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The following breaking changes are documented on this page:
1414
| [EnvelopedCms defaults to AES-256 encryption](#envelopedcms-defaults-to-aes-256-encryption) | 3.0 |
1515
| [Minimum size for RSAOpenSsl key generation has increased](#minimum-size-for-rsaopenssl-key-generation-has-increased) | 3.0 |
1616
| [.NET Core 3.0 prefers OpenSSL 1.1.x to OpenSSL 1.0.x](#net-core-30-prefers-openssl-11x-to-openssl-10x) | 3.0 |
17+
| [CryptoStream.Dispose transforms final block only when writing](#cryptostreamdispose-transforms-final-block-only-when-writing) | 3.0 |
1718
| [Boolean parameter of SignedCms.ComputeSignature is respected](#boolean-parameter-of-signedcmscomputesignature-is-respected) | 2.1 |
1819

1920
## .NET 5.0
@@ -40,6 +41,10 @@ The following breaking changes are documented on this page:
4041

4142
***
4243

44+
[!INCLUDE [CryptoStream.Dispose transforms final block only when writing](~/includes/core-changes/cryptography/3.0/cryptography-cryptostream-dispose-final-block-write.md)]
45+
46+
***
47+
4348
## .NET Core 2.1
4449

4550
[!INCLUDE [Boolean parameter of SignedCms.ComputeSignature is respected](~/includes/core-changes/cryptography/2.1/compute-signature-silent-parameter.md)]
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
### CryptoStream.Dispose transforms final block only when writing
2+
3+
The <xref:System.Security.Cryptography.CryptoStream.Dispose%2A?displayProperty=nameWithType> method, which is used to finish `CryptoStream` operations, no longer attempts to transform the final block when reading.
4+
5+
#### Change description
6+
7+
In previous .NET versions, if a user performed an incomplete read when using <xref:System.Security.Cryptography.CryptoStream> in <xref:System.Security.Cryptography.CryptoStreamMode.Read> mode, the <xref:System.Security.Cryptography.CryptoStream.Dispose%2A> method could throw an exception (for example, when using AES with padding). The exception was thrown because the final block was attempted to be transformed but the data was incomplete.
8+
9+
In .NET Core 3.0 and later versions, <xref:System.Security.Cryptography.CryptoStream.Dispose%2A> no longer tries to transform the final block when reading, which allows for incomplete reads.
10+
11+
#### Reason for change
12+
13+
This change enables incomplete reads from the crypto stream when a network operation is cancelled, without the need to catch an exception.
14+
15+
#### Version introduced
16+
17+
3.0
18+
19+
#### Recommended action
20+
21+
Most apps should not be affected by this change.
22+
23+
If your application previously caught an exception in case of an incomplete read, you can delete that `catch` block.
24+
If your app used transforming of the final block in hashing scenarios, you might need to ensure that the entire stream is read before it's disposed.
25+
26+
#### Category
27+
28+
Cryptography
29+
30+
#### Affected APIs
31+
32+
- <xref:System.Security.Cryptography.CryptoStream.Dispose%2A?displayProperty=fullName>
33+
34+
<!--
35+
36+
#### Affected APIs
37+
38+
- `M:System.Security.Cryptography.CryptoStream.Dispose`
39+
40+
-->

0 commit comments

Comments
 (0)