我目前正在开发一个用C++编写的项目,该项目利用CryptoAPI执行Diffie-Hellman密钥交换.我在使用这个工作时遇到了一些麻烦,因为我得到的最终RC4会话密钥不能用于加密Python中的相同文本(使用pycrypto).
执行Diffie-Hellman密钥交换的C++代码取自msdn,但此处包含后代:
#include <tchar.h>
#include <windows.h>
#include <wincrypt.h>
#pragma comment(lib, "crypt32.lib")
// The key size, in bits.
#define DHKEYSIZE 512
// Prime in little-endian format.
static const BYTE g_rgbPrime[] =
{
0x91, 0x02, 0xc8, 0x31, 0xee, 0x36, 0x07, 0xec,
0xc2, 0x24, 0x37, 0xf8, 0xfb, 0x3d, 0x69, 0x49,
0xac, 0x7a, 0xab, 0x32, 0xac, 0xad, 0xe9, 0xc2,
0xaf, 0x0e, 0x21, 0xb7, 0xc5, 0x2f, 0x76, 0xd0,
0xe5, 0x82, 0x78, 0x0d, 0x4f, 0x32, 0xb8, 0xcb,
0xf7, 0x0c, 0x8d, 0xfb, 0x3a, 0xd8, 0xc0, …
Run Code Online (Sandbox Code Playgroud)