如何在.netcore / Linux中实现Diffie Hellman [英] How to implement Diffie Hellman in .netcore/Linux

查看:168
本文介绍了如何在.netcore / Linux中实现Diffie Hellman的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ECDiffieHellmanCng ->不支持平台

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

ECDiffieHellmanOpenSsl -> PublicKey.ToByteArray() -> Platform not supported

这里的问题基本上是相同的(未回答)别人,7个月前
如何在Linux上对ECDiffieHellmanOpenSsl的公钥进行序列化和反序列化?

Here's basically the same (unanswered) question from someone else, 7 months ago How do I serialize and deserialize the public key for ECDiffieHellmanOpenSsl on Linux?

如果可以的话,我想避免拉入第三方部门驯服提供的类。

I'd like to avoid pulling in 3rd party deps if there's a way to tame the provided classes.

推荐答案

ECDiffieHellmanCng 在Linux上不受支持。

ECDiffieHellmanCng is not supported on Linux.

Linux使用 ECDiffieHellmanOpenSsl ,但请注意

Linux uses ECDiffieHellmanOpenSsl, but note


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

The types involved do not translate between platforms

请参见 https://github.com/dotnet/corefx/blob/1841042b99062de13dc80098cede9413be569ite/cross-ation platform-cryptography.md

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

You can find some examples of how this is used in the test suite, for example

[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/coreaxfffff69/bf0fbf0fbf0fbfbf0fbfbf0fbfcbf0fcbf0fbc0fbfbf0fbfc0fbc0fb0fbc0fbf0fbc0f0fbc0f0fbc0f0fbc0f0fbf0fbc0f0fbc0f0fbc0f0fbc0f0fbc0fbf0fbc0fbfbf0fbfbf0fbfbfbf0fbbfbfbf0fbbfbfbf以来就就就好了/System.Security.Cryptography.OpenSsl/tests/EcDiffieHellmanOpenSslTests.cs

这篇关于如何在.netcore / Linux中实现Diffie Hellman的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆