27

I'm asking this question because I've spent the best part of a day trawling through msdn docs and other opaque sources for simple straightforward guidelines on how to get started with the Windows C/C++ Crypto API.

What I'd like to see is some example code, typical include paths, linking guidelines, etc, anything useful really. I know this is an imprecise question but I reckon imprecise answers are better none at all.

I'll get the ball rolling with my own meager findings...

blami
  • 6,588
  • 2
  • 23
  • 31
Gearoid Murphy
  • 11,834
  • 17
  • 68
  • 86

4 Answers4

27

Here's a bunch of examples I've found....

MSDN has these examples scattered around the docs

This website provides a good overview of the concepts along with cross-platform examples

Gearoid Murphy
  • 11,834
  • 17
  • 68
  • 86
17

The msdn docs are here: http://msdn.microsoft.com/en-us/library/aa380252.aspx

This is the main include file: #include <wincrypt.h>

The cryptography bits are included as part of the Windows SDK, which is typically installed in %PROGRAMFILES(x86)%\Microsoft SDKs\Windows\SDKVERSION (e.g., C:\Program Files\Microsoft SDKs\Windows\v6.0A). The headers are typically in %WINDOWSSDK%\Include, and the related libraries are in %WINDOWSSDK%\Lib.

You must link to the cryptography libraries explicitly. Assuming you're in Visual Studio, you can add the reference by right clicking on the C++ project, choosing properties, and selecting Configuration Properties -> Linker on the treeview at left. You can then specify crypt32.lib in the input field on the right.

Alternately, (assuming you're using msvc++) add

#pragma comment(lib, "crypt32.lib")

to your source.

Billy ONeal
  • 104,103
  • 58
  • 317
  • 552
Gearoid Murphy
  • 11,834
  • 17
  • 68
  • 86
6

There is also a lengthy example "Encryption using the Win32 Crypto API" over at the Code Project.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
0

After searching for several hours, I found this one here: https://learn.microsoft.com/en-us/troubleshoot/windows/win32/get-information-authenticode-signed-executables

It's detailed, and it works.

Kim Homann
  • 3,042
  • 1
  • 17
  • 20