Tag: diffie hellman

使用C#进行ECDHE密钥交换

我正在尝试使用.net进行TLS 1.2的ECDHE密钥交换。 服务器正在响应server_key_exchange消息,该消息以04开头,所以我猜它是未加密的。 根据我的理解,消息的前32位被视为值X,接下来的32位被视为值Y.使用这些和椭圆曲线(例如secp256r1),创建服务器的公钥值。 我指的是来自OpenTLS的以下python代码: class ECDHE_RSA_Key_Exchange: def __init__(self, server_key_exchange): curve_code = bytes_to_hex(server_key_exchange[5:7]) print(‘Elliptic curve: ‘ + elliptic_curves[curve_code]) self.curve = reg.get_curve(elliptic_curves[curve_code]) x = bytes_to_int(server_key_exchange[9:9+32]) y = bytes_to_int(server_key_exchange[9+32:9+64]) self.server_pubKey = ec.Point(self.curve, x, y) 正在寻找C#资源来实现同样的目标。 以下是我可以做的一些移植: int skeLen = this.sKeyExch_hs[7]; skeLen = skeLen – 1; byte[] sPubKey = new byte[skeLen]; Buffer.BlockCopy(this.sKeyExch_hs, 9, sPubKey, 0, skeLen); ECDiffieHellmanCng ecdhCngClient […]

.NET中的ECDiffieHellmanCng是否具有实现NIST SP 800-56A的密钥派生函数,第5.8.1节

我有一项任务需要使用NIST SP 800-56A第5.8.1节中描述的密钥导出函数来获取密钥材料。 我不是密码学方面的专家,所以如果问题是天真的,请原谅。 这是我到目前为止所做的: 我有另一方的公钥和我的私钥 现在我尝试使用C#(。NET 4)ECDiffieHellmanCng类使用ECDH 1.3.132.1.12生成共享密钥,如下所示: // The GetCngKey method reads the private key from a certificate in my Personal certificate store CngKey cngPrivateKey = GetCngKey(); ECDiffieHellmanCng ecDiffieHellmanCng = new ECDiffieHellmanCng(cngPrivateKey); ecDiffieHellmanCng.HashAlgorithm = CngAlgorithm.ECDiffieHellmanP256; ecDiffieHellmanCng.KeyDerivationFunction = ?? // What do I set here 最后这样做: ecDiffieHellmanCng.DeriveKeyMaterial(otherPartyPublicKey:); 在哪里/如何设置其他参数算法ID,Party U Info,Party V Info? 编辑我愿意使用像Bouncy Castle这样的其他库(前提是它们可以从.NET调用)