Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 什么是System.Security.Cryptography';DeriveKeyFromHash()实际上是什么?_C#_.net_Cryptography_System.security - Fatal编程技术网

C# 什么是System.Security.Cryptography';DeriveKeyFromHash()实际上是什么?

C# 什么是System.Security.Cryptography';DeriveKeyFromHash()实际上是什么?,c#,.net,cryptography,system.security,C#,.net,Cryptography,System.security,我正在一个C#app和一个在C.System.security.Cryptography中编程的嵌入式设备之间实现一个安全交换。关于它的任何加密算法在“引擎盖下”做什么,我都没有文档。我需要知道这一点,以便在C中实现同样的东西,我有更多的基本库。具体来说,我想知道ECDiffieHellman.DeriveKeyFromHash(HashAlgorithmName.SHA256)做什么 我已经尝试过关闭API,但最终在ncrypt.h中调用了非托管NCryptDeriveKey 该方法似乎并不简

我正在一个C#app和一个在C.System.security.Cryptography中编程的嵌入式设备之间实现一个安全交换。关于它的任何加密算法在“引擎盖下”做什么,我都没有文档。我需要知道这一点,以便在C中实现同样的东西,我有更多的基本库。具体来说,我想知道ECDiffieHellman.DeriveKeyFromHash(HashAlgorithmName.SHA256)做什么

我已经尝试过关闭API,但最终在ncrypt.h中调用了非托管NCryptDeriveKey

该方法似乎并不简单地执行共享秘密的SHA256哈希。我在C端做了这个,得到了一个不同的值。我知道在C#端接收到的公钥是有效的,因为否则,前面的方法会抛出异常。我猜数据是附加的或是前置的,正如一些NIST文件所规定的那样,但这是事实吗?还是我还遗漏了什么

编辑:原来我在C端做错了什么。对C#行为的额外确认有助于缩小搜索范围

ECDiffieHellmanCng ecdh = new ECDiffieHellmanCng(myEccKeys);

//This would throw an exception if PeerRawPublicKey was invalid.
var PeerPublicKey = ECDiffieHellmanCngPublicKey.FromByteArray(PeerRawPublicKey.ToArray(), CngKeyBlobFormat.EccPublicBlob);

//How is keyMaterial generated?
byte[] keyMaterial = ecdh.DeriveKeyFromHash(PeerPublicKey, HashAlgorithmName.SHA256, null, null);

它只计算
散列(prepend | | Z | | append)
,其中Z是共享秘密的X坐标

对于prepend和append,空值都被视为空