PCQQ ECDHアルゴリズムC++実現
11709 ワード
Opensslライブラリはご自身でインストールしてください
#include
#include
using namespace std;
#pragma comment(lib,"libssl.lib")
#pragma comment(lib,"libcrypto.lib")
int main(){
unsigned char pub_key[25] = {};
unsigned char sha_key[16] = {};
//QQ tk, , 8.9
unsigned char tk[49] = { 0x04, 0xBF, 0x47, 0xA1, 0xCF, 0x78, 0xA6, 0x29, 0x66, 0x8B,
0x0B, 0xC3, 0x9F, 0x8E, 0x54, 0xC9, 0xCC, 0xF3, 0xB6, 0x38,
0x4B, 0x08, 0xB8, 0xAE, 0xEC, 0x87, 0xDA, 0x9F, 0x30, 0x48,
0x5E, 0xDF, 0xE7, 0x67, 0x96, 0x9D, 0xC1, 0xA3, 0xAF, 0x11,
0x15, 0xFE, 0x0D, 0xCC, 0x8E, 0x0B, 0x17, 0xCA, 0xCF
};
EC_KEY* ec_key = EC_KEY_new_by_curve_name(NID_secp192k1);
const EC_GROUP* ec_group = EC_KEY_get0_group(ec_key);
EC_POINT* ec_point = EC_POINT_new(ec_group);
if (EC_KEY_generate_key(ec_key) == 1){
EC_POINT_point2oct(ec_group, EC_KEY_get0_public_key(ec_key), POINT_CONVERSION_COMPRESSED, pub_key, 25, 0);
if (EC_POINT_oct2point(ec_group, ec_point, tk, 49, 0) == 1){
ECDH_compute_key(sha_key, 16, ec_point, ec_key, 0);
}
}
for (int i = 0; i < sizeof(pub_key) / sizeof(unsigned char); i++){
printf("%X ",pub_key[i]);
}
printf("
");
for (int i = 0; i < sizeof(sha_key) / sizeof(unsigned char); i++){
printf("%X ", sha_key[i]);
}
getchar();
}