21.05.2003 8:30:29The key BLOB type is not supported Ответов: 1
Куканов в.В.
Импортирую из файла сессионный ключ. Ругается что
The key BLOB type is not supported by this CSP and is possibly invalid.

if(!CryptImportKey(hProv,pbKeyBlob,dwBlobLen,hXchgKey,0,&hKey))
{
res=GetLastError();
if(res==ERROR_BUSY) AfxMessageBox("Some CSPs set this error if a private key is imported into a container while another thread or process is using this key.");
if(res==ERROR_INVALID_HANDLE) AfxMessageBox("One of the parameters specifies an invalid handle. ");
if(res==ERROR_INVALID_PARAMETER) AfxMessageBox("One of the parameters contains an invalid value. This is most often an invalid pointer.");
if(res==NTE_BAD_ALGID) AfxMessageBox("The simple key BLOB you are trying to import is not encrypted with the expected key exchange algorithm.");
if(res==NTE_BAD_DATA) AfxMessageBox("Either the algorithm that works with the public key you are trying to import is not supported by this CSP, or an attempt was made to import a session key that was encrypted with something other than one of your public keys.");
if(res==NTE_BAD_FLAGS) AfxMessageBox("The dwFlags parameter specified is invalid.");
if(res==NTE_BAD_TYPE) AfxMessageBox("The key BLOB type is not supported by this CSP and is possibly invalid.");
if(res==NTE_BAD_UID) AfxMessageBox("The hProv parameter does not contain a valid context handle.");
if(res==NTE_BAD_VER) AfxMessageBox("The key BLOB’s version number does not match the CSP version. This usually indicates that the CSP needs to be upgraded. ");
}

А вот как я его экспортирую:
// Экспорт сессионного ключа
// Determine size of the key blob, and allocate memory.
free(pbKeyBlob);
dwBlobLen=0;
if(!CryptExportKey(hKey,hOpenKey,SIMPLEBLOB,0,NULL,&dwBlobLen))
{
res=GetLastError();
if(res==ERROR_INVALID_HANDLE) AfxMessageBox("One of the parameters specifies an invalid handle. ");
if(res==ERROR_INVALID_PARAMETER) AfxMessageBox("One of the parameters contains an invalid value. This is most often an invalid pointer.");
if(res==ERROR_MORE_DATA) AfxMessageBox("If the buffer specified by the pbData parameter is not large enough to hold the returned data, the function sets the ERROR_MORE_DATA code and stores the required buffer size, in bytes, in the variable pointed to by pdwcbDataLen.");
if(res==NTE_BAD_FLAGS) AfxMessageBox("The dwFlags parameter is nonzero.");
if(res==NTE_BAD_KEY) AfxMessageBox("One or both of the keys specified by hKey and hExpKey are invalid.");
if(res==NTE_BAD_KEY_STATE) AfxMessageBox("You do not have permission to export the key. That is, when the hKey key was created, the CRYPT_EXPORTABLE flag was not specified.");
if(res==NTE_BAD_PUBLIC_KEY) AfxMessageBox("The key BLOB type specified by dwBlobType is PUBLICKEYBLOB, but hExpKey does not contain a public key handle.");
if(res==NTE_BAD_TYPE) AfxMessageBox("The dwBlobType parameter specifies an unknown BLOB type.");
if(res==NTE_BAD_UID) AfxMessageBox("The CSP context that was specified when the hKey key was created cannot be found.");
if(res==NTE_NO_KEY) AfxMessageBox("A session key is being exported, and the hExpKey parameter does not specify a public key.");
}
pbKeyBlob =(BYTE *)malloc(dwBlobLen);
// export to the file session key
if(!CryptExportKey(hKey,hOpenKey,SIMPLEBLOB,0,pbKeyBlob,&dwBlobLen))
{
TRACE("error exporting session key");
}
ExportSessionSenderKey.Open("ExportSessionSenderKey.dat",CFile::modeCreate | CFile::modeWrite);
ExportSessionSenderKey.Write(pbKeyBlob,dwBlobLen); // запись непосредственно блоба.
free(pbKeyBlob);// clean up the pbKeyBlob
 
Ответы:
21.05.2003 8:43:02kure
Где посмотреть примеры:

http://www.cryptopro.ru/CryptoPro/forum/myforum.asp?q=4

http://www.cryptopro.ru/CryptoPro/test/sample2_0.zip

Исходники примеров. Файл export.c