views:

264

answers:

1

I need to decrypt some data files with wincrypt and examples are few and far between online. The most solid example I've found is here. However, this is using all sorts of types I cannot seem to find information about (CBase64Utils, CString, etc).

I am reading the final solution, trying to understand the process, and have come to this:

// 5. Determine the LENGTH of the BUFFER to hold the corresponding cyphertext.
            CBase64Utils bu;
            int ipszSourceLen = strlen(pszSource);
            char *pszSource2 = bu.Decode(pszSource, &ipszSourceLen);

            DWORD   dwSourceLen = strlen(pszSource2);      // Get the length of the input string.
            DWORD   dwDataLen = dwSourceLen;
            BYTE*   pTarget = NULL;
            DWORD   dwCryptDataLen = dwDataLen;
            CryptEncrypt(hKey, 0, TRUE, 0, NULL, &dwCryptDataLen, dwDataLen);

This is pure chinese to me. Can anybody make sense of it and hopefully clear some muddy waters? Thanks

A: 

The code you linked is horrible. It appears the fellow wrote his encrypt method, and then subsequently wrote his decrypt method simply by copying and pasting the first method and making a few changes (yet leaving a ton of code left over from the encryption process). I wouldn't be surprised if it works, it's just that it wastes time and space doing useless work left over from encryption (plus the comments are all backwards).

As wincrypt is a Microsoft library, there are plenty of examples over at the MSDN. As MSDN samples are (usually) well-written and well-commented, they should be much easier to understand, so I would recommend you look at them instead.

GRB