You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc_source/best-practices.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
The AWS Encryption SDK is designed to make it easy for you to protect your data using industry standards and best practices\. While many best practices are selected for you in default values, some practices are optional but recommended whenever it's practical\.
4
4
5
5
**Use the latest version**
6
-
When you start using the AWS Encryption SDK, use the latest version offered in your preferred [programming language](programming-languages.md)\. If you've been using the AWS Encryption SDK, upgrade to each latest version as soon as possible\. This assures that you're using the recommended configuration and taking advantage of new security properties to protect your data\. For details about supported versions, including guidance for migration and deployment, see [Migrating to version 2\.0\.*x*](migration.md)\.
6
+
When you start using the AWS Encryption SDK, use the latest version offered in your preferred [programming language](programming-languages.md)\. If you've been using the AWS Encryption SDK, upgrade to each latest version as soon as possible\. This assures that you're using the recommended configuration and taking advantage of new security properties to protect your data\. For details about supported versions, including guidance for migration and deployment, see [Support and maintenance](introduction.md#support) and [Versions of the AWS Encryption SDK](about-versions.md)\.
7
7
If a new version deprecates elements in your code, replace them as soon as you can\. Deprecation warnings and code comments typically recommend a good alternative\.
8
8
To make significant upgrades easier and less prone to error, we occasionally provide a temporary or transitional release\. Use these releases, and their accompanying documentation, to assure that you can upgrade your application without disrupting your production workflow\.
Copy file name to clipboardExpand all lines: doc_source/c-examples.md
+36-18
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
The following examples show you how to use the AWS Encryption SDK for C to encrypt and decrypt data\.
4
4
5
-
The examples in this section show how to use version 2\.0\.*x* and later of the AWS Encryption SDK for C\. For examples that use earlier versions, find your release in the [Releases](https://github.com/aws/aws-encryption-sdk-c/releases) list of the [aws\-encryption\-sdk\-c repository](https://github.com/aws/aws-encryption-sdk-c/) repository on GitHub\.
5
+
The examples in this section show how to use versions 2\.0\.*x* and later of the AWS Encryption SDK for C\. For examples that use earlier versions, find your release in the [Releases](https://github.com/aws/aws-encryption-sdk-c/releases) list of the [aws\-encryption\-sdk\-c repository](https://github.com/aws/aws-encryption-sdk-c/) repository on GitHub\.
6
6
7
7
When you install and build the AWS Encryption SDK for C, the source code for these and other examples are included in the `examples` subdirectory, and they are compiled and built into the `build` directory\. You can also find them in the [examples](https://github.com/aws/aws-encryption-sdk-c/tree/master/examples) subdirectory of the [aws\-encryption\-sdk\-c](https://github.com/aws/aws-encryption-sdk-c/) repository on GitHub\.
8
8
@@ -13,9 +13,9 @@ When you install and build the AWS Encryption SDK for C, the source code for the
13
13
14
14
The following example shows you how to use the AWS Encryption SDK for C to encrypt and decrypt a string\.
15
15
16
-
This example features the KMS [keyring](concepts.md#keyring), a type of keyring that uses an AWS KMS key in [AWS Key Management Service \(AWS KMS\)](https://aws.amazon.com/kms/) to generate and encrypt data keys\. The example includes some code written in C\+\+ because the AWS Encryption SDK for C uses the AWS SDK for C\+\+ to call AWS KMS\.
16
+
This example features the [AWS KMS keyring](use-kms-keyring.md), a type of keyring that uses an AWS KMS key in [AWS Key Management Service \(AWS KMS\)](https://docs.aws.amazon.com/kms/latest/developerguide/) to generate and encrypt data keys\. The example includes code written in C\+\+\. The AWS Encryption SDK for C requires the AWS SDK for C\+\+ to call AWS KMS when using AWS KMS keyrings\.If you're using a keyring that doesn't interact with AWS KMS, such as a raw AES keyring, a raw RSA keyring, or a multi\-keyring that doesn't include an AWS KMS keyring, the AWS SDK for C\+\+ is not required\.
17
17
18
-
For help creating an AWS KMS key, see [Creating Keys](https://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html) in the *AWS Key Management Service Developer Guide*\. For help identifying the AWS KMS keys in an AWS KMS keyring, see [Identifying AWS KMS keys in an AWS KMS keyring](use-kms-keyring.md#kms-keyring-id)
18
+
For help creating an AWS KMS key, see [Creating Keys](https://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html) in the *AWS Key Management Service Developer Guide*\. For help identifying the AWS KMS keys in an AWS KMS keyring, see [Identifying AWS KMS keys in an AWS KMS keyring](use-kms-keyring.md#kms-keyring-id)\.
19
19
20
20
**See the complete code sample**: [string\.cpp](https://github.com/aws/aws-encryption-sdk-c/blob/master/examples/string.cpp)
21
21
@@ -27,7 +27,16 @@ For help creating an AWS KMS key, see [Creating Keys](https://docs.aws.amazon.co
27
27
28
28
The first part of this example uses an AWS KMS keyring with one AWS KMS key to encrypt a plaintext string\.
29
29
30
-
Step 1: Construct the keyring\.
30
+
Step 1\. Load error strings\.
31
+
Call the `aws_cryptosdk_load_error_strings()` method in your C or C\+\+ code\. It loads error information that is very useful for debugging\.
32
+
You only need to call it once, such as in your `main` method\.
33
+
34
+
```
35
+
/* Load error strings for debugging */
36
+
aws_cryptosdk_load_error_strings();
37
+
```
38
+
39
+
Step 2: Construct the keyring\.
31
40
Create an AWS KMS keyring for encryption\. The keyring in this example is configured with one AWS KMS key, but you can configure an AWS KMS keyring with multiple AWS KMS keys, including AWS KMS keys in different AWS Regions and different accounts\.
32
41
To identify an AWS KMS key in an encryption keyring in the AWS Encryption SDK for C, specify a [key ARN](https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id-key-ARN) or [alias ARN](https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id-alias-arn)\. In a decryption keyring, you must use a key ARN\. For details, see [Identifying AWS KMS keys in an AWS KMS keyring](use-kms-keyring.md#kms-keyring-id)\.
33
42
[Identifying AWS KMS keys in an AWS KMS keyring](use-kms-keyring.md#kms-keyring-id)
Create a session using the allocator, a mode enumerator, and the keyring\.
46
55
Every session requires a mode: either `AWS_CRYPTOSDK_ENCRYPT` to encrypt or `AWS_CRYPTOSDK_DECRYPT` to decrypt\. To change the mode of an existing session, use the `aws_cryptosdk_session_reset` method\.
47
56
After you create a session with the keyring, you can release your reference to the keyring using the method that the SDK provides\. The session retains a reference to the keyring object during its lifetime\. References to the keyring and session objects are released when you destroy the session\. This [reference counting](c-language-using.md#c-language-using-release) technique helps to prevent memory leaks and to prevent the objects from being released while they are in use\.
@@ -50,16 +59,16 @@ After you create a session with the keyring, you can release your reference to t
// When you add the keyring to the session, release the keyring object
62
+
/* When you add the keyring to the session, release the keyring object */
54
63
aws_cryptosdk_keyring_release(kms_keyring);
55
64
```
56
65
57
-
Step 3: Set the encryption context\.
66
+
Step 4: Set the encryption context\.
58
67
An [encryption context](concepts.md#encryption-context) is arbitrary, non\-secret additional authenticated data\. When you provide an encryption context on encrypt, the AWS Encryption SDK cryptographically binds the encryption context to the ciphertext so that the same encryption context is required to decrypt the data\. Using an encryption context is optional, but we recommend it as a best practice\.
59
68
First, create a hash table that includes the encryption context strings\.
60
69
61
70
```
62
-
// Allocate a hash table for the encryption context.
71
+
/* Allocate a hash table for the encryption context */
63
72
int set_up_enc_ctx(struct aws_allocator *alloc, struct aws_hash_table *my_enc_ctx)
To encrypt the plaintext string, use the `aws_cryptosdk_session_process_full` method with the session in encryption mode\. This method, introduced in AWS Encryption SDK versions 1\.9\.*x* and 2\.2\.*x*, is designed for non\-streaming encryption and decryption\. To handle streaming data, call the `aws_cryptosdk_session_process` in a loop\.
86
95
When encrypting, the plaintext fields are input fields; the ciphertext fields are output fields\. When the processing is complete, the `ciphertext_output` field contains the [encrypted message](concepts.md#message), including the actual ciphertext, encrypted data keys, and the encryption context\. You can decrypt this encrypted message by using the AWS Encryption SDK for any supported programming language\.
87
96
88
97
```
89
-
// Gets the length of the plaintext that the session processed
98
+
/* Gets the length of the plaintext that the session processed */
90
99
size_t ciphertext_len_output;
91
100
if (AWS_OP_SUCCESS != aws_cryptosdk_session_process_full(session,
92
101
ciphertext_output,
@@ -99,15 +108,24 @@ if (AWS_OP_SUCCESS != aws_cryptosdk_session_process_full(session,
99
108
}
100
109
```
101
110
102
-
Step 5: Clean up the session\.
111
+
Step 6: Clean up the session\.
103
112
The final step destroys the session including references to the CMM and the keyring\.
104
113
If you prefer, instead of destroying the session, you can reuse the session with the same keyring and CMM to decrypt the string, or to encrypt or decrypt other messages\. To use the session for decrypting, use the `aws_cryptosdk_session_reset` method to change the mode to `AWS_CRYPTOSDK_DECRYPT`\.
105
114
106
115
### Decrypt a string<aname="c-example-string-decrypt"></a>
107
116
108
117
The second part of this example decrypts an encrypted message that contains the ciphertext of the original string\.
109
118
110
-
Step 1: Construct the keyring\.
119
+
Step 1: Load error strings\.
120
+
Call the `aws_cryptosdk_load_error_strings()` method in your C or C\+\+ code\. It loads error information that is very useful for debugging\.
121
+
You only need to call it once, such as in your `main` method\.
122
+
123
+
```
124
+
/* Load error strings for debugging */
125
+
aws_cryptosdk_load_error_strings();
126
+
```
127
+
128
+
Step 2: Construct the keyring\.
111
129
When you decrypt data in AWS KMS, you pass in the [encrypted message](concepts.md#message) that the encrypt API returned\. The [Decrypt API](https://docs.aws.amazon.com/kms/latest/APIReference/API_Decrypt.html) doesn't take an AWS KMS key as input\. Instead, AWS KMS uses the same AWS KMS key to decrypt the ciphertext that it used to encrypt it\. However, the AWS Encryption SDK lets you specify an AWS KMS keyring with AWS KMS keys on encrypt and decrypt\.
112
130
On decrypt, you can configure a keyring with only the AWS KMS keys that you want to use to decrypt the encrypted message\. For example, you might want to create a keyring with only the AWS KMS key that is used by a particular role in your organization\. The AWS Encryption SDK will never use an AWS KMS key unless it appears in the decryption keyring\. If the SDK can't decrypt the encrypted data keys by using the AWS KMS keys in the keyring that you provide, either because none of AWS KMS keys in the keyring were used to encrypt any of the data keys, or because the caller doesn't have permission to use the AWS KMS keys in the keyring to decrypt, the decrypt call fails\.
113
131
When you specify an AWS KMS key for a decryption keyring, you must use its [key ARN](https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id-key-ARN)\.[Alias ARNs](https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id-alias-arn) are permitted only in encryption keyrings\. For help identifying the AWS KMS keys in an AWS KMS keyring, see [Identifying AWS KMS keys in an AWS KMS keyring](use-kms-keyring.md#kms-keyring-id)\.
Create a session using the allocator and the keyring\. To configure the session for decryption, configure the session with the `AWS_CRYPTOSDK_DECRYPT` mode\.
125
143
After you create a session with a keyring, you can release your reference to the keyring using the method that the SDK provides\. The session retains a reference to the keyring object during its lifetime, and both the session and keyring are released when you destroy the session\. This reference counting technique helps to prevent memory leaks and to prevent the objects from being released while they are in use\.
// When you add the keyring to the session, release the keyring object
149
+
/* When you add the keyring to the session, release the keyring object */
132
150
aws_cryptosdk_keyring_release(kms_keyring);
133
151
```
134
152
135
-
Step 3: Decrypt the string\.
153
+
Step 4: Decrypt the string\.
136
154
To decrypt the string, use the `aws_cryptosdk_session_process_full` method with the session that is configured for decryption\. This method, introduced in AWS Encryption SDK versions 1\.9\.*x* and 2\.2\.*x*, is designed for non\-streaming encryption and decryption\. To handle streaming data, call the `aws_cryptosdk_session_process` in a loop\.
137
155
When decrypting, the ciphertext fields are input fields and the plaintext fields are output fields\. The `ciphertext_input` field holds the [encrypted message](message-format.md) that the encrypt method returned\. When the processing is complete, the `plaintext_output` field contains the plaintext \(decrypted\) string\.
138
156
@@ -150,7 +168,7 @@ if (AWS_OP_SUCCESS != aws_cryptosdk_session_process_full(session,
150
168
}
151
169
```
152
170
153
-
Step 4: Verify the encryption context\.
171
+
Step 5: Verify the encryption context\.
154
172
Be sure that the actual encryption context — the one that was used to decrypt the message — contains the encryption context that you provided when encrypting the message\. The actual encryption context might include extra pairs, because the [cryptographic materials manager](concepts.md#crypt-materials-manager)\(CMM\) can add pairs to the provided encryption context before encrypting the message\.
155
173
In the AWS Encryption SDK for C, you are not required to provide an encryption context when decrypting because the encryption context is included in the encrypted message that the SDK returns\. But, before it returns the plaintext message, your decrypt function should verify that all pairs in the provided encryption context appear in the encryption context that was used to decrypt the message\.
156
174
First, get a read\-only pointer to the hash table in the session\. This hash table contains the encryption context that was used to decrypt the message\.
@@ -175,8 +193,8 @@ for (struct aws_hash_iter iter = aws_hash_iter_begin(my_enc_ctx); !aws_hash_iter
175
193
}
176
194
```
177
195
178
-
Clean up the session\.
179
-
After you verify the encryption context, you can destroy the session\. As usual, you can reuse the session\. If you need to reconfigure it, use the `aws_cryptosdk_session_reset` method\.
196
+
Step 6: Clean up the session\.
197
+
After you verify the encryption context, you can destroy the session, or reuse it\. If you need to reconfigure the session, use the `aws_cryptosdk_session_reset` method\.
Copy file name to clipboardExpand all lines: doc_source/c-language-installation.md
+5-1
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,10 @@
2
2
3
3
You can find detailed instructions for installing and building the AWS Encryption SDK for C in the [README file](https://github.com/aws/aws-encryption-sdk-c/#readme) of the [aws\-encryption\-sdk\-c](https://github.com/aws/aws-encryption-sdk-c/) repository\. It includes instructions for building on Amazon Linux, Ubuntu, macOS, and Windows platforms\.
4
4
5
-
Before you begin, decide whether you want to use [AWS KMS keyrings](use-kms-keyring.md) in the AWS Encryption SDK\. If you use an AWS KMS keyring, you need to install the AWS SDK for C\+\+\. AWS KMS keyrings use [AWS Key Management Service](https://docs.aws.amazon.com/kms/latest/developerguide/)\(AWS KMS\) to generate and protect the encryption keys that protect your data\. Otherwise, you need to generate and protect your own raw wrapping keys\.
5
+
Before you begin, decide whether you want to use [AWS KMS keyrings](use-kms-keyring.md) in the AWS Encryption SDK\. If you use an AWS KMS keyring, you need to install the AWS SDK for C\+\+\. The AWS SDK is required to interact with [AWS Key Management Service](https://docs.aws.amazon.com/kms/latest/developerguide/)\(AWS KMS\)\. When you use AWS KMS keyrings, the AWS Encryption SDK uses AWS KMS to generate and protect the encryption keys that protect your data\.
6
+
7
+
You do not need to install the AWS SDK for C\+\+ if you are using another keyring type, such as a raw AES keyring, a raw RSA keyring, or a multi\-keyring that doesn't include an AWS KMS keyring\. However, when using a raw keyring type, you need to generate and protect your own raw wrapping keys\.
8
+
9
+
For help deciding which keyring types to use, see [Choosing a keyring](which-keyring.md)\.
6
10
7
11
If you're having trouble with your installation, [file an issue](https://github.com/aws/aws-encryption-sdk-c/issues) in the `aws-encryption-sdk-c` repository or use any of the feedback links on this page\.
0 commit comments