Re: CryptImportKey & PLAINTEXTKEYBLOB

From: Michel Gallant (neutron_at_istar.ca)
Date: 06/28/04


Date: Sun, 27 Jun 2004 21:14:11 -0400

EofOne keys can also be useful in understanding how "things work" .. e.g.
  http://www.jensign.com/JavaScience/dotnet/NetDESEncrypt
- Mitch Gallant
   MVP Security

"Ryan Menezes [MSFT]" <ryanmen@online.microsoft.com> wrote in message news:%23%231ypYKXEHA.3716@TK2MSFTNGP11.phx.gbl...
> 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
> >
>
>