如何在.netcore / Linux中实现Diffie Hellman

问题描述 投票:2回答:1

[ECDiffieHellmanCng->不支持平台

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

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

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

c# .net-core cryptography diffie-hellman
1个回答
0
投票

ECDiffieHellmanCng在Linux上不受支持。

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

© www.soinside.com 2019 - 2024. All rights reserved.