

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 适用于 AWS CloudHSM 客户端 SDK 3 的 PKCS \$111 库的代码示例
<a name="pkcs11-v3-samples"></a>

上的代码示例 GitHub 向您展示了如何使用 PKCS \$111 库完成基本任务。 AWS CloudHSM

## 示例代码先决条件
<a name="pkcs11-v3-samples-prereqs"></a>

在运行示例之前，请执行以下步骤以设置您的环境：
+ 为客户端软件开发工具包 3 安装和配置 [PKCS \$111 库](install-pkcs11-v3.md)。
+ 设置[加密用户 (CU)](manage-hsm-users.md)。您的应用程序使用此 HSM 账户在 HSM 运行代码示例。

## 代码示例
<a name="pkcs11-v3-samples-code"></a>

PKCS \$111 AWS CloudHSM 软件库的代码样本可在上找到。[GitHub](https://github.com/aws-samples/aws-cloudhsm-pkcs11-examples)此存储库包括有关如何使用 PKCS\$111 执行常见操作的示例，包括加密、解密、签名和验证。
+ [生成密钥（AES、RSA、EC）](https://github.com/aws-samples/aws-cloudhsm-pkcs11-examples/tree/master/src/generate)
+ [列出密钥属性](https://github.com/aws-samples/aws-cloudhsm-pkcs11-examples/blob/master/src/attributes/)
+ [使用 AES GCM 加密和解密数据](https://github.com/aws-samples/aws-cloudhsm-pkcs11-examples/blob/master/src/encrypt/aes_gcm.c)
+ [使用 AES\$1CTR 加密和解密数据](https://github.com/aws-samples/aws-cloudhsm-pkcs11-examples/tree/master/src/encrypt/aes_ctr.c) 
+ [使用 3DES 加密和解密数据](https://github.com/aws-samples/aws-cloudhsm-pkcs11-examples/tree/master/src/encrypt/des_ecb.c) 
+ [使用 RSA 对数据进行签名和验证](https://github.com/aws-samples/aws-cloudhsm-pkcs11-examples/blob/master/src/sign/rsa_sign.c)
+ [使用 HMAC KDF 派生密钥](https://github.com/aws-samples/aws-cloudhsm-pkcs11-examples/blob/master/src/derivation/hmac_kdf.c)
+ [使用 AES 对密钥进行包装和解开包装（使用 PKCS \$15 填充）](https://github.com/aws-samples/aws-cloudhsm-pkcs11-examples/blob/master/src/wrapping/aes_wrapping.c)
+ [使用 AES 对密钥进行包装和解开包装（无填充）](https://github.com/aws-samples/aws-cloudhsm-pkcs11-examples/blob/master/src/wrapping/aes_no_padding_wrapping.c)
+ [使用 AES 包装和解开密钥（使用零填充）](https://github.com/aws-samples/aws-cloudhsm-pkcs11-examples/blob/master/src/wrapping/aes_zero_padding_wrapping.c)
+ [使用 AES-GCM 对密钥进行包装和解开包装](https://github.com/aws-samples/aws-cloudhsm-pkcs11-examples/tree/master/src/wrapping/aes_gcm_wrapping.c)
+ [使用 RSA 对密钥进行包装和解开包装](https://github.com/aws-samples/aws-cloudhsm-pkcs11-examples/blob/master/src/wrapping/rsa_wrapping.c)