CryptImportKey & PLAINTEXTKEYBLOB
From: Oleg Leikin (Leikin_at_discussions.microsoft.com)
Date: 06/27/04
- Next message: Pieter Philippaerts: "Re: CryptImportKey & PLAINTEXTKEYBLOB"
- Previous message: tlviewer: "Re: Encrypting BLOB exported by MS Base DSS and DH CSP"
- Next in thread: Pieter Philippaerts: "Re: CryptImportKey & PLAINTEXTKEYBLOB"
- Reply: Pieter Philippaerts: "Re: CryptImportKey & PLAINTEXTKEYBLOB"
- Reply: tlviewer: "Re: CryptImportKey & PLAINTEXTKEYBLOB"
- Reply: Ryan Menezes [MSFT]: "Re: CryptImportKey & PLAINTEXTKEYBLOB"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Sun, 27 Jun 2004 09:11:01 -0700
Hi All,
the same code works under XP and fails under 2000 (GetLastError returns NTE_BAD_TYPE ater CryptImportKey is executed):
.......................................
DWORD keyBlobLength = 0;
BYTE* pKeyBlob = NULL;
Key2PLAINTEXTKEYBLOB(CALG_3DES, pKeyBase, keyBaseLength, &pKeyBlob,keyBlobLength);
if(!pKeyBlob)
return false;
// import key to CSP
if(!CryptImportKey( hProv,
pKeyBlob,
keyBlobLength,
NULL,
0,
&hKey
))
{
delete pKeyBlob;
return false;
}
.......................................
where Key2PLAINTEXTKEYBLOB:
//////////////
Key2PLAINTEXTKEYBLOB(ALG_ID alg, BYTE* pKey, DWORD keyLength, BYTE** ppKeyBlob, DWORD &keyBlobLength)
{
// allocate blob
keyBlobLength = 2 * sizeof(BYTE) + sizeof(WORD) + sizeof(ALG_ID) + sizeof(DWORD) + keyLength;
*ppKeyBlob = new BYTE[keyBlobLength];
if(*ppKeyBlob)
{
// init blob header
BYTE type = PLAINTEXTKEYBLOB;
BYTE version = CUR_BLOB_VERSION;
WORD reserved = 0;
int index = 0;
// blob type
(*ppKeyBlob)[index] = type;
index ++;
// blob version
(*ppKeyBlob)[index] = version;
index ++;
// reserved
memcpy((*ppKeyBlob) + index, (WORD*)&reserved, sizeof(WORD));
index += sizeof(WORD);
// key alg
memcpy((*ppKeyBlob) + index, (ALG_ID*)&alg, sizeof(ALG_ID));
index += sizeof(ALG_ID);
// key length
memcpy((*ppKeyBlob) + index, (DWORD*)&keyLength, sizeof(DWORD));
index += sizeof(DWORD);
// key
memcpy((*ppKeyBlob) + index, pKey, keyLength);
}
else
keyBlobLength = 0;
}
//////////////
Thanks in advance for any clue !
Oleg
- Next message: Pieter Philippaerts: "Re: CryptImportKey & PLAINTEXTKEYBLOB"
- Previous message: tlviewer: "Re: Encrypting BLOB exported by MS Base DSS and DH CSP"
- Next in thread: Pieter Philippaerts: "Re: CryptImportKey & PLAINTEXTKEYBLOB"
- Reply: Pieter Philippaerts: "Re: CryptImportKey & PLAINTEXTKEYBLOB"
- Reply: tlviewer: "Re: CryptImportKey & PLAINTEXTKEYBLOB"
- Reply: Ryan Menezes [MSFT]: "Re: CryptImportKey & PLAINTEXTKEYBLOB"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]