Window C/C++ Crypto API 示例和技巧

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4796590/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 16:31:54  来源:igfitidea点击:

Window C/C++ Crypto API Examples and tips

c++cwindowscryptoapimscapi

提问by Gearoid Murphy

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.

我问这个问题是因为我花了一天中最好的时间浏览 msdn 文档和其他不透明的来源,以获取有关如何开始使用 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...

我会用我自己微薄的发现让球滚动......

回答by Gearoid Murphy

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

msdn 文档在这里:http: //msdn.microsoft.com/en-us/library/aa380252.aspx

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

这是主要的包含文件: #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.

加密位作为Windows SDK 的一部分包含在内,它通常安装在%PROGRAMFILES(x86)%\Microsoft SDKs\Windows\SDKVERSION(例如C:\Program Files\Microsoft SDKs\Windows\v6.0A)中。头文件通常%WINDOWSSDK%\Include%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.libin the input field on the right.

您必须明确链接到加密库。假设您在 Visual Studio 中,您可以通过右键单击 C++ 项目,选择属性,然后在左侧的树视图中选择配置属性 -> 链接器来添加引用。然后您可以crypt32.lib在右侧的输入字段中指定。

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

或者,(假设您使用的是 msvc++)添加

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

to your source.

到您的来源。

回答by Uwe Keim

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

在代码项目中还有一个冗长的示例使用 Win32 Crypto API 进行加密