gpt4 book ai didi

c - 使用 cryptoapi CryptImportKey 导入公钥时出错

转载 作者:行者123 更新时间:2023-12-02 02:19:20 24 4
gpt4 key购买 nike

我想将公钥 blob 导入到 CSP。但发生错误。

BYTE pbData[] ={0xEB,0x2A,0x38,0x56,0x86,0x61,0x88,0x7F,0xA1,0x80,0xBD,0xDB,0x5C,0xAB,0xD5,0xF2,0x1C,0x7B,0xFD,0x59,0xC0,0x90,0xCB,0x2D,0x24,0x5A,0x87,0xAC,0x25,0x30,0x62,0x88,0x27,0x29,0x29,0x3E,0x55,0x06,0x35,0x05,0x08,0xE7,0xF9,0xAA,0x3B,0xB7,0x7F,0x43,0x33,0x23,0x14,0x90,0xF9,0x15,0xF6,0xD6,0x3C,0x55,0xFE,0x2F,0x08,0xA4,0x9B,0x35,0x3F,0x44,0x4A,0xD3,0x99,0x3C,0xAC,0xC0,0x2D,0xB7,0x84,0xAB,0xBB,0x8E,0x42,0xA9,0xB1,0xBB,0xFF,0xFB,0x38,0xBE,0x18,0xD7,0x8E,0x87,0xA0,0xE4,0x1B,0x9B,0x8F,0x73,0xA9,0x28,0xEE,0x0C,0xCE,0xE1,0xF6,0x73,0x98,0x84,0xB9,0x77,0x7E,0x4F,0xE9,0xE8,0x8A,0x1B,0xBE,0x49,0x59,0x27,0xAC,0x4A,0x79,0x9B,0x31,0x81,0xD6,0x44,0x24,0x43};
USHORT modulusLengthInBytes = sizeof(pbData);
HCRYPTKEY hPublicKey;
DWORD keyBlobLength = sizeof(BLOBHEADER)+sizeof(RSAPUBKEY)+modulusLengthInBytes;
BYTE* keyBlob = (BYTE*)malloc(keyBlobLength);
BLOBHEADER* blobheader = (BLOBHEADER*) keyBlob;
blobheader->bType = PUBLICKEYBLOB;
blobheader->bVersion = CUR_BLOB_VERSION;
blobheader->reserved = 0;
blobheader->aiKeyAlg = CALG_RSA_KEYX;
RSAPUBKEY* rsapubkey = (RSAPUBKEY*)keyBlob + sizeof(BLOBHEADER);
rsapubkey->magic = 0x31415352;
rsapubkey->bitlen = modulusLengthInBytes*8;
rsapubkey->pubexp = 65537; // Or whatever your public exponent is.
BYTE* modulus = keyBlob + sizeof(BLOBHEADER) + sizeof(RSAPUBKEY);
memcpy(modulus, pbData, modulusLengthInBytes);
bRet = CryptImportKey(hProv, keyBlob, keyBlobLength, 0, 0, &hPublicKey);
if (!bRet)
{
dwRet = GetLastError();
}

CryptImportKey 返回 0,dwRet 为 0x80090004(NTE_BAD_LEN)。我非常确定长度是正确的。但仍然出现同样的错误。

最佳答案

RSAPUBKEY* rsapubkey = (RSAPUBKEY*)keyBlob + sizeof(BLOBHEADER);

应该改为阅读

RSAPUBKEY* rsapubkey = (RSAPUBKEY*) (keyBlob + sizeof(BLOBHEADER));

关于c - 使用 cryptoapi CryptImportKey 导入公钥时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14838123/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com