Skip to content

Example uses Obsolete API #11723

@bcdev-com

Description

@bcdev-com

Type of issue

Outdated article

Description

The sample code provided includes:

alicePublicKey = alice.PublicKey.ToByteArray();

but ECDiffieHellmanPublicKey.ToByteArray() is marked as Obsolete in current versions of dotnet, and what it produces throws when passed to CngKey.Import, at least for Curve25519. The recommended replacement, ECDiffieHellmanPublicKey.ExportSubjectPublicKeyInfo() also throws for Curve25519.

The least bad replacement I could figure out is the very unsatisfying:

var alicePublicKey = (alice.PublicKey as ECDiffieHellmanCngPublicKey)!.Import().Export(CngKeyBlobFormat.EccFullPublicBlob);

and then

CngKey.Import(alicePublicKey, CngKeyBlobFormat.EccFullPublicBlob)

to create something that can be used with DeriveKeyMaterial() et al.

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.ecdiffiehellmancng?view=net-9.0

Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.Security.Cryptography/ECDiffieHellmanCng.xml

Document Version Independent Id

f761f563-a2d2-32f8-f34e-3e88927076e4

Platform Id

6403fb7b-63f1-302c-9c2a-5c3f84f63994

Article author

@dotnet-bot

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-area-labelAn area label is needed to ensure this gets routed to the appropriate area ownersuntriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions