Re: CryptImportKey & PLAINTEXTKEYBLOB
From: tlviewer (tlviewerSHRUB_at_yahoo.CHENEY.com)
Date: 06/27/04
- Next message: Ryan Menezes [MSFT]: "Re: CryptImportKey & PLAINTEXTKEYBLOB"
- Previous message: Pieter Philippaerts: "Re: CryptImportKey & PLAINTEXTKEYBLOB"
- In reply to: Oleg Leikin: "CryptImportKey & PLAINTEXTKEYBLOB"
- Next in thread: Ryan Menezes [MSFT]: "Re: CryptImportKey & PLAINTEXTKEYBLOB"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Sun, 27 Jun 2004 14:40:09 -0700
"Oleg Leikin" <Oleg Leikin@discussions.microsoft.com> wrote in message news:EE8702F1-F7F1-4FCC-9008-CD6EC68FA7DB@microsoft.com...
> 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
>
In Win2k and Win98 your
Key2PLAINTEXTKEYBLOB()
helper function should pack a SIMPLEBLOB, rather than a
PLAINTEXTKEYBLOB. Further, the lower modulus needs to be RSA encrypted with
the Pbk of the context. If you can figure out how to pack one, doing the other
should be easy.
good luck,
tlviewer
- Next message: Ryan Menezes [MSFT]: "Re: CryptImportKey & PLAINTEXTKEYBLOB"
- Previous message: Pieter Philippaerts: "Re: CryptImportKey & PLAINTEXTKEYBLOB"
- In reply to: Oleg Leikin: "CryptImportKey & PLAINTEXTKEYBLOB"
- Next in thread: Ryan Menezes [MSFT]: "Re: CryptImportKey & PLAINTEXTKEYBLOB"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]