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
Window C/C++ Crypto API Examples and tips
提问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
Here's a bunch of examples I've found....
这是我找到的一堆例子......
- Example C Program: Listing the Certificates in a Store
- Example C Program: Using CryptAcquireContext
- Example C Program: Enumerating CSP Providers and Provider Types
- Example C Code for Opening Certificate Stores
- Example C Program: Sending and Receiving a Signed and Encrypted Message
- Example C Program: Signing a Hash and Verifying the Hash Signature
- 示例 C 程序:列出商店中的证书
- 示例 C 程序:使用 CryptAcquireContext
- 示例 C 程序:枚举 CSP 提供程序和提供程序类型
- 用于打开证书存储的示例 C 代码
- 示例 C 程序:发送和接收已签名和加密的消息
- 示例 C 程序:签名散列并验证散列签名
MSDN has these examples scattered around the docs
MSDN 将这些示例分散在文档中
This websiteprovides a good overview of the concepts along with cross-platform examples
该网站很好地概述了这些概念以及跨平台示例
回答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.lib
in 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 进行加密”。