|
| 1 | +--- |
| 2 | +title: "Breaking change - CoseSigner.Key may now be null" |
| 3 | +description: "Learn about the breaking change in .NET 10 where CoseSigner.Key may now be null when backed by Post-Quantum Cryptography algorithms." |
| 4 | +ms.date: 08/07/2025 |
| 5 | +ai-usage: ai-assisted |
| 6 | +ms.custom: https://github.com/dotnet/docs/issues/46999 |
| 7 | +--- |
| 8 | + |
| 9 | +# CoseSigner.Key can now be null |
| 10 | + |
| 11 | +In .NET 10, the <xref:System.Security.Cryptography.Cose.CoseSigner.Key?displayProperty=nameWithType> property can now return `null`. If `CoseSigner` is backed by an RSA or ECDSA key, then `CoseSigner.Key` returns a non-null key. However, when `CoseSigner` is backed by a key that doesn't derive from <xref:System.Security.Cryptography.AsymmetricAlgorithm>, like `MLDsa` (a new Post-Quantum Cryptography (PQC) signing algorithm), `CoseSigner.Key` returns `null`. |
| 12 | + |
| 13 | +## Version introduced |
| 14 | + |
| 15 | +.NET 10 Preview 7 |
| 16 | + |
| 17 | +## Previous behavior |
| 18 | + |
| 19 | +`CoseSigner.Key` couldn't be `null`. It had type `AsymmetricAlgorithm`. |
| 20 | + |
| 21 | +## New behavior |
| 22 | + |
| 23 | +`CoseSigner.Key` can be `null`. Its type is `AsymmetricAlgorithm?`. |
| 24 | + |
| 25 | +```csharp |
| 26 | +using RSA rsaKey = RSA.Create(); |
| 27 | + |
| 28 | +CoseSigner signer = new CoseSigner(rsaKey, RSASignaturePadding.Pss, HashAlgorithmName.SHA512); |
| 29 | +// signer.Key is rsaKey here. |
| 30 | +
|
| 31 | +// CoseKey is a new abstraction for all keys used in COSE. |
| 32 | +CoseKey coseKey = new CoseKey(rsaKey, RSASignaturePadding.Pss, HashAlgorithmName.SHA512); |
| 33 | +signer = new CoseSigner(coseKey); |
| 34 | +// signer.Key is rsaKey here. |
| 35 | +
|
| 36 | +using MLDsa mldsa = MLDsa.GenerateKey(MLDsaAlgorithm.MLDsa44); |
| 37 | + |
| 38 | +coseKey = new CoseKey(mldsa); |
| 39 | +signer = new CoseSigner(coseKey); |
| 40 | +// signer.Key is null here. |
| 41 | +``` |
| 42 | + |
| 43 | +## Type of breaking change |
| 44 | + |
| 45 | +This is a [behavioral change](../../categories.md#behavioral-change) but it can also affect [source compatibility](../../categories.md#source-compatibility). |
| 46 | + |
| 47 | +## Reason for change |
| 48 | + |
| 49 | +With the introduction of new signing algorithms such as ML-DSA, .NET has moved away from using `AsymmetricAlgorithm` as the universal base class for all asymmetric algorithms. Likewise, `CoseSigner` can now be constructed with a key that doesn't derive from `AsymmetricAlgorithm`. In this case `CoseSigner.Key` can't return an `AsymmetricAlgorithm` representing the underlying key and thus returns `null` instead. |
| 50 | + |
| 51 | +## Recommended action |
| 52 | + |
| 53 | +It's still okay to use `CoseSigner.Key` but be sure to handle `null` values. |
| 54 | + |
| 55 | +## Affected APIs |
| 56 | + |
| 57 | +- <xref:System.Security.Cryptography.Cose.CoseSigner.Key?displayProperty=fullName> |
0 commit comments