SOL9 2.0 Sample: HMAC

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * HMAC.cpp 
 * Copyright (c) 2009 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


//2009/02/17

#include <sol/crypt/CryptServiceProvider.h>
#include <sol/crypt/KeyedMessageDigest.h>


int _tmain(int argc, TCHAR** argv)
{
    int rc = 0;
    if (argc != 2) {
        printf("Usage:HMAC.exe filePath\n");
        return rc;
    }

    try {
        CryptServiceProvider csp;
        ALG_ID hashAlgId = CALG_SHA1;
        ALG_ID keyAlgId  = CALG_RC4;

        KeyedMessageDigest hmac(csp, CALG_HMAC, hashAlgId, keyAlgId);

        HMAC_INFO   hmacInfo; 
        ZeroMemory(&hmacInfo, sizeof(hmacInfo));
        hmacInfo.HashAlgid = hashAlgId;
        hmac.setHashParam(HP_HMAC_INFO, (BYTE*)&hmacInfo);

        hmac.hashFile(argv[1]);

        Bytes bytes;
        hmac.getHashValue(bytes);

        printf("HMAC:\n");
        bytes.dump();


    } catch (Exception& ex) {
        printf("Exception = %s\n", ex.getErrorMessage());
    }

    rc = GetLastError();

    return rc;
}

Last modified: 11 Nov 2009

Copyright (c) 2009 Antillia.com ALL RIGHTS RESERVED.