在 .NET 10 中, CoseSigner.Key 该属性现在可以返回 null。 如果 CoseSigner 由 RSA 或 ECDSA 密钥提供支持,则 CoseSigner.Key 返回非 null 密钥。 当CoseSigner由不从AsymmetricAlgorithm派生的密钥(例如新的后量子加密(PQC)签名算法MLDsa)支持时,CoseSigner.Key会返回null。
已引入的版本
.NET 10 预览版 7
以前的行为
              CoseSigner.Key无法成为null。 其类型为 AsymmetricAlgorithm。
新行为
              CoseSigner.Key 可以是 null。 其类型为 AsymmetricAlgorithm?.
using RSA rsaKey = RSA.Create();
CoseSigner signer = new CoseSigner(rsaKey, RSASignaturePadding.Pss, HashAlgorithmName.SHA512);
// signer.Key is rsaKey here.
// CoseKey is a new abstraction for all keys used in COSE.
CoseKey coseKey = new CoseKey(rsaKey, RSASignaturePadding.Pss, HashAlgorithmName.SHA512);
signer = new CoseSigner(coseKey);
// signer.Key is rsaKey here.
using MLDsa mldsa = MLDsa.GenerateKey(MLDsaAlgorithm.MLDsa44);
coseKey = new CoseKey(mldsa);
signer = new CoseSigner(coseKey);
// signer.Key is null here.
破坏性变更的类型
更改原因
随着新的签名算法(如 ML-DSA)的引入,.NET 已不再用作 AsymmetricAlgorithm 所有非对称算法的通用基类。 同样,现在可以使用一个不从 AsymmetricAlgorithm 派生的密钥来构造 CoseSigner。 在这种情况下 CoseSigner.Key ,不能返回 AsymmetricAlgorithm 表示基础键,因此返回 null 。
建议的措施
它仍然可以使用 CoseSigner.Key ,但请务必处理 null 值。