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