c# - 带有 ECDHsaCng 的 ECDH 签名
问题描述
我正在与使用 AES-CCM 加密的设备通信,我需要使用 ECDH 派生的密钥进行设置。我的机器证书在 TPM 中有一个 ECC 私钥。
我对此有些陌生,所以请多多包涵。
这是我现在正在查看的代码。这是用我的证书签署密钥的正确方法吗?
//this will actually be loaded by another method. Only here for demo purposes;
X509Certificate2 masterEndEntityCert;
//we are using the NST p-256 curve
using (var ecdh = new ECDiffieHellmanCng(ECCurve.NamedCurves.nistP256))
{
//our HKDF should be HMAC
ecdh.KeyDerivationFunction = ECDiffieHellmanKeyDerivationFunction.Hmac;
ecdh.HashAlgorithm = CngAlgorithm.Sha256;
//get the ephemeral key to send to the other device
var ephemeralKey = ecdh.PublicKey.ToByteArray();
//get the ecdsa private key from my cert for signing
using (var alg = masterEndEntityCert.GetECDsaPrivateKey() as ECDsaCng)
{
//sign the sha256 hash of the key
var sig = alg.SignData(ephemeralKey, HashAlgorithmName.SHA256);
//concat the ephemeral key and the signed hash together for transmission
this.SignedEphemeralPublicKey = ephemeralKey.Concat(sig).ToArray();
}
}
解决方案
推荐阅读
- python - Python 3D 散点图 - 使用分类变量调整颜色
- python - .pyc 文件的 pdb:源代码字符串不能包含空字节
- c# - 按下 Escape 按钮退出应用程序
- node.js - facebook 页面访问令牌以获取用户个人资料
- django - ModuleNotFoundError:在 Django 中没有名为“app.myapp”的模块
- javascript - Set 如何与 JavaScript 中的单链表中的 Get 配合使用?
- sap - SAP BusinessObject Webi - 将 Excel 数据提供程序中的值与 Universe 中的变量匹配
- javascript - django成功功能中的ajax不起作用
- python - 我正在尝试显示 wordcloud 图像,但出现 ValueError: We need at least 1 word to plot a word cloud, got 0
- html - 当我开始页面或点击任何地方时,如何让我的单选按钮已经被选中