generate/import a key for HMAC

From: Peter Barber (Barber_at_discussions.microsoft.com)
Date: 01/05/05

  • Next message: mmicko_at_gmail.com: "Reading server certificate"
    Date: Wed, 5 Jan 2005 07:37:09 -0800
    
    

    HI,

    How do I generate a key (or import a plain text key) for use with HMAC? The
    key is a MD4 hash.

    I have tried using CryptDeriveKey(hcrypt, CALG_HMAC, hKhash, 0,&hKkey) where
    hKhash is a MD4 hash object.

    Also I have tried using CryptImportKey with the plain text RC4 hash (rough
    code snippit follows) but each time I get an 'Invalid algorithm specified'
    error.

    struct
    {
        BLOBHEADER header;
        DWORD keysize;
        BYTE key[16];
    } Krawblob;
    memset(&Krawblob, 0, sizeof(Krawblob));

    Krawblob.header.bType = PLAINTEXTKEYBLOB;
    Krawblob.header.bVersion = CUR_BLOB_VERSION;
    Krawblob.header.aiKeyAlg = CALG_HMAC;
    Krawblob.keysize = 16;

    DWORD dwDummy = 16;
    ::CryptGetHashParam(hKhash, HP_HASHVAL, Krawblob.key, &dwDummy, 0);

    DATA_BLOB Kblob;
    memset(&Kblob, 0, sizeof(Kblob));
    Kblob.cbData = sizeof(Krawblob);
    Kblob.pbData = (BYTE*)&Krawblob;

    ::CryptImportKey(hcrypt, Kblob.pbData, Kblob.cbData, NULL, 0, &hKkey);

    Thanks Pete


  • Next message: mmicko_at_gmail.com: "Reading server certificate"