如何在 .netcore/Linux 中实现 Diffie Hellman [英] How to implement Diffie Hellman in .netcore/Linux
问题描述
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?
如果有办法驯服所提供的课程,我想避免引入 3rd 方 deps.
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
您可以找到一些在测试套件中如何使用它的示例,例如
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/corefx/blob/a10890f4ffe0fadf090c922578ba0e606ebdd16c/src/System.Security.Cryptography.OpenSsl/tests/EcDiffieHellmanOpenSslTests.cs
这篇关于如何在 .netcore/Linux 中实现 Diffie Hellman的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!