ECDiffieHellmanOpenSsl

ECDiffieHellmanOpenSsl

ECDiffieHellmanCng->不支持平台

ECDiffieHellmanOpenSsl-> PublicKey.ToByteArray()->不支持平台

这基本上是7个月前其他人的相同问题(未回答)
How do I serialize and deserialize the public key for ECDiffieHellmanOpenSsl on Linux?

如果有办法驯服所提供的课程,我想避免参加第三方代表。

最佳答案

Linux不支持ECDiffieHellmanCng

Linux使用ECDiffieHellmanOpenSsl,但请注意


  涉及的类型不会在平台之间转换


https://github.com/dotnet/corefx/blob/1841042b99062de13dc80098cede9413be569238/Documentation/architecture/cross-platform-cryptography.md

您可以找到一些在测试套件中如何使用它的示例,例如

[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

09-15 11:47