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

问题描述

ECDiffieHellmanCng ->不支持平台

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

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

这里的问题基本上是相同的(未回答)别人,7个月前

Here's basically the same (unanswered) question from someone else, 7 months agoHow 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

请参见

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

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);
    }
}

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

07-31 20:31