Re: CryptImportKey & PLAINTEXTKEYBLOB
From: Ryan Menezes [MSFT] (ryanmen_at_online.microsoft.com)
Date: 06/28/04
- Previous message: tlviewer: "Re: CryptImportKey & PLAINTEXTKEYBLOB"
- In reply to: Oleg Leikin: "CryptImportKey & PLAINTEXTKEYBLOB"
- Next in thread: Michel Gallant: "Re: CryptImportKey & PLAINTEXTKEYBLOB"
- Reply: Michel Gallant: "Re: CryptImportKey & PLAINTEXTKEYBLOB"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Sun, 27 Jun 2004 17:23:39 -0700
You will need to use exponent-of-one key for W2k and W98.
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q228/7/86.ASP&NoWebContent=1
--
Thanks,
Ryan Menezes [MS]
This posting is provided "AS IS" with no warranties, and confers no rights.
"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
>
- Previous message: tlviewer: "Re: CryptImportKey & PLAINTEXTKEYBLOB"
- In reply to: Oleg Leikin: "CryptImportKey & PLAINTEXTKEYBLOB"
- Next in thread: Michel Gallant: "Re: CryptImportKey & PLAINTEXTKEYBLOB"
- Reply: Michel Gallant: "Re: CryptImportKey & PLAINTEXTKEYBLOB"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]