共用方式為


CoseSigner.Key 現在可以是 Null

在 .NET 10 中 CoseSigner.Key ,屬性現在可以傳回 null。 如果 CoseSigner 由 RSA 或 ECDSA 金鑰支援,則 CoseSigner.Key 傳回非 Null 金鑰。 不過,當 由不是衍生自 CoseSigner的金鑰所支援時AsymmetricAlgorithm,例如 MLDsa (新的後量子密碼編譯 (PQC) 簽署演算法),CoseSigner.Key會傳null回 。

推出的版本

.NET 10

先前的行為

以前,CoseSigner.Key 無法 null。 其類型為 AsymmetricAlgorithm

新行為

從 .NET 10 開始, 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 非對稱演算法的通用基類。 同樣地, CoseSigner 現在可以使用不是衍生自 AsymmetricAlgorithm的索引鍵來建構。 在這裡情況下 CoseSigner.Key ,無法傳回 AsymmetricAlgorithm 代表基礎索引鍵的 ,因此會改為傳 null 回 。

使用仍然沒問題, CoseSigner.Key 但請務必處理 null 值。

受影響的 API