I'm trying to use this API and I go through the keyexchange,validate certs,get driver public key & random number, encode the AMCoppSignature。
First:
when i want to "Importing the Drivers Public Key" following the sample COde, CryptImportKey() will cause program exception。 The pointer pkey should point to the position after rsapubkey, but in the current writing, the position pkey points to shifts by 132 bytes
Because the prspubkkey type is rsapubkey*。
// The next block of data is the RSAPUBKEY structure.
RSAPUBKEY *pRsaPubKey = (RSAPUBKEY*)(pBlob + sizeof(PUBLICKEYSTRUC));
pRsaPubKey->magic = RSA1; // Public key.
pRsaPubKey->bitlen = cbModulus * 8; // Number of bits in the modulus.
pRsaPubKey->pubexp = dwExponent; // Exponent.
// Copy the modulus into the blob. Put the modulus directly after the
// RSAPUBKEY structure in the blob.
BYTE *pKey = (BYTE*)(pRsaPubkey + sizeof(RSAPUBKEY));
CopyMemory(pKey, pModulus, cbModulus);
// Now import the key.
HCRYPTKEY hRSAKey; // Receives a handle to the key.
CryptImportKey(hCSP, pBlob, cbKeyBlob, 0, 0, &hRSAKey)
Second : According to the sample Code , Initiating a COPP Session Fail,NTE_BAD_LEN from CryptEncrypt().
AMCOPPSignature CoppSig;
ZeroMemory(&CoppSig, sizeof(CoppSig));
// Copy the signature data into CoppSig. (Not shown.)
// Encrypt the signature:
const DWORD RSA_PADDING = 11; // 11-byte padding.
DWORD cbDataOut = sizeof(AMCOPPSignature);
DWORD cbDataIn = cbDataOut - RSA_PADDING;
CryptEncrypt(
hRSAKey,
NULL, // No hash object.
TRUE, // Final block to encrypt.
0, // Reserved.
&CoppSig, // COPP signature.
&cbDataOut,
cbDataIn
);