ECDiffieHellmanCng n'est pas pris en charge sous Linux.
Linux utilise ECDiffieHellmanOpenSsl, mais notez
Les types impliqués ne traduisent pas entre les plates-formes
Voir https://github.com/dotnet/corefx/blob/1841042b99062de13dc80098cede9413be569238/Documentation/architecture/cross-platform-cryptography.md
Vous pouvez trouver quelques exemples d'utilisation dans la suite de tests, par exemple
[Fact]
public void VerifyDuplicateKey_ValidHandle()
{
using (var first = new ECDiffieHellmanOpenSsl())
using (SafeEvpPKeyHandle firstHandle = first.DuplicateKeyHandle())
using (ECDiffieHellman second = new ECDiffieHellmanOpenSsl(firstHandle))
using (ECDiffieHellmanPublicKey firstPublic = first.PublicKey)
using (ECDiffieHellmanPublicKey secondPublic = second.PublicKey)
{
byte[] firstSecond = first.DeriveKeyFromHash(secondPublic, HashAlgorithmName.SHA256);
byte[] secondFirst = second.DeriveKeyFromHash(firstPublic, HashAlgorithmName.SHA256);
byte[] firstFirst = first.DeriveKeyFromHash(firstPublic, HashAlgorithmName.SHA256);
Assert.Equal(firstSecond, secondFirst);
Assert.Equal(firstFirst, firstSecond);
}
}
https://github.com/dotnet/corefx/blob/a10890f4ffe0fadf090c922578ba0e606ebdd16c/src/System.Security.Cryptography.OpenSsl/tests/EcDiffieHellmanOpenSslTests.cs