【发布时间】:2020-11-28 21:06:21
【问题描述】:
我正在开发一个 C#-Server,它将与 Python-Client 通信。我想使用 AES 加密消息,并且我想使用 Diffie Hellmann 进行密钥交换。
当我尝试服务器加载客户端发送的公钥时,我收到 CryptographicException,告诉我参数错误。
这是我的 C# 代码:
using System.Security.Cryptography;
//...
ECDiffieHellmanCng dh = new ECDiffieHellmanCng();
dh.KeyDerivationFunction = ECDiffieHellmanKeyDerivationFunction.Hash;
dh.HashAlgorithm = CngAlgorithm.Sha256;
BigInteger integer = BigInteger.Parse(key); // key (string) contains the public key sent by the client
// Here is the error:
CngKey foreignKey = CngKey.Import(integer.ToByteArray(), CngKeyBlobFormat.EccPublicBlob);
byte[] key = dh.DeriveKeyMaterial(foreignKey);
Python-代码:
import pyDH
d1 = pyDH.DiffieHellman()
pubkey = d1.gen_public_key() // This is the huge prime number which gets sent to the server
您可以在以下位置找到 Python 库 https://pypi.org/project/pyDH/
感谢您的回答!
【问题讨论】:
标签: python c# encryption diffie-hellman