Skip to content

[Breaking change]: ECDiffieHellmanPublicKey.ToByteArray() and the associated constructor are now Obsolete #28861

Closed

Description

@bartonjs

Description

The ECDiffieHellmanPublicKey.ToByteArray() method does not have an implied file format, and for the built-in implementations it throws PlatformNotSupportedException on all non-Windows Operating Systems. Since ECDiffieHellmanPublicKey also has a standard format export (via the ExportSubjectPublicKeyInfo() method) we have declared the older member obsolete.

Version

.NET 7 Preview 4

Previous behavior

Calling ECDiffieHellmanPublicKey.ToByteArray() or the protected ECDiffieHellmanPublicKey(byte[]) constructor would not produce a warning.

New behavior

Calling ECDiffieHellmanPublicKey.ToByteArray() or the protected ECDiffieHellmanPublicKey(byte[]) constructor produces warning SYSLIB0043.

Type of breaking change

  • Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load/execute or different run-time behavior.
  • Source incompatible: Source code may encounter a breaking change in behavior when targeting the new runtime/component/SDK, such as compile errors or different run-time behavior.

Reason for change

The method was not supported on all operating systems that .NET supports and on the ones it does support the data format was not a standard format.

Recommended action

For callers exporting the public key value, use the ExportSubjectPublicKeyInfo() method.

For existing derived types that already call the protected ECDiffieHellmanPublicKey(byte[]) constructor, continue calling the constructor and suppress the SYSLIB0043 warning.

For new derived types (or existing derived types that do not currently call the byte[]-based constructor) skip calling the protected ECDiffieHellmanPublicKey(byte[]) constructor, and either override ToByteArray() to throw an exception, or accept the default behavior of returning an empty array.

Feature area

Cryptography

Affected APIs

M:System.Security.Cryptography.ECDiffieHellmanPublicKey.#ctor(System.Byte[])
M:System.Security.Cryptography.ECDiffieHellmanPublicKey.ToByteArray()

Activity

  1. added
    breaking-change
    on Mar 30, 2022
  2. added
    ⌚ Not Triaged
    🏁 Release: .NET 7
    source incompatible
    on Mar 30, 2022
  3. Tohnmeister commented on Oct 22, 2024

    @Tohnmeister

    Does making this method obsolete, mean that it will be removed in a future .NET version? Especially consdering that one of the recommendation is to suppress the warning/error in case of existing derived types that already callt he byte[] based constructor.

  4. bartonjs commented on Oct 22, 2024

    @bartonjs
    MemberAuthor

    Does making this method obsolete, mean that it will be removed in a future .NET version?

    We generally don't "remove" things, as that would make assemblies that called them get MissingMethodExceptions. We could replace the method body with throw new PlatformNotSupportedException(), but that's not super likely in this case, it's not code we have an active reason to delete.

    The reason it got marked as Obsolete is that callers using the base type have no idea what ToByteArray is going to do, and they can't really do anything with the value it returns (without knowing what specific derived type it came from). So, no one should ever be calling it.

    FWIW, there's a 80+% chance that the whole of ECDiffieHellmanPublicKey will be marked as Obsolete in the next version (or, at least, all the members accepting or producing one), and the API simplified to do DeriveKey in terms of another ECDiffieHellman object (since the ECDHPK values are only ever produced off of an ECDH object).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🏁 Release: .NET 7breaking-changesource incompatible

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions