Skip to content

Commit 04c3746

Browse files
committed
minor edits
1 parent 0721a43 commit 04c3746

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

examples/src/keyrings/file_streaming_example.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
33
"""
4-
This example demonstrates file streaming for encryption and decryption using a Raw AES keyring
4+
This example demonstrates file streaming for encryption and decryption.
55
6-
The Raw AES keyring lets you use an AES symmetric key that you provide as a wrapping key that
7-
protects your data key. You need to generate, store, and protect the key material,
8-
preferably in a hardware security module (HSM) or key management system. Use a Raw AES keyring
9-
when you need to provide the wrapping key and encrypt the data keys locally or offline.
6+
File streaming is useful when the plaintext or ciphertext file/data is too large to load into
7+
memory. Therefore, the AWS Encryption SDK allows users to stream the data, instead of loading it
8+
all at once in memory. In this example, we demonstrate file streaming for encryption and decryption
9+
using a Raw AES keyring. However, you can use any keyring for encryption/decryption with streaming.
10+
11+
For more information on how to use Raw AES keyrings, see
12+
https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/use-raw-aes-keyring.html
13+
To look at a Raw AES keyring example, checkout out raw_aes_keyring_example.py
1014
1115
This example creates a Raw AES Keyring and then encrypts an input stream from the file
1216
`plaintext_filename` with an encryption context to an output (encrypted) file `ciphertext_filename`.
@@ -21,8 +25,6 @@
2125
you specify as a byte array. You can specify only one wrapping key in each Raw AES keyring,
2226
but you can include multiple Raw AES keyrings, alone or with other keyrings, in a multi-keyring.
2327
24-
For more information on how to use Raw AES keyrings, see
25-
https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/use-raw-aes-keyring.html
2628
"""
2729
import filecmp
2830
import secrets
@@ -48,7 +50,7 @@ def encrypt_and_decrypt_with_keyring(
4850
ciphertext_filename: str,
4951
decrypted_filename: str
5052
):
51-
"""Demonstrate a streaming encrypt/decrypt cycle using a Raw AES keyring.
53+
"""Demonstrate a streaming encrypt/decrypt cycle.
5254
5355
Usage: encrypt_and_decrypt_with_keyring(plaintext_filename
5456
ciphertext_filename
@@ -98,6 +100,7 @@ def encrypt_and_decrypt_with_keyring(
98100
static_key = secrets.token_bytes(32)
99101

100102
# 5. Create a Raw AES keyring
103+
# We choose to use a raw AES keyring, but any keyring can be used with streaming.
101104
mat_prov: AwsCryptographicMaterialProviders = AwsCryptographicMaterialProviders(
102105
config=MaterialProvidersConfig()
103106
)

examples/src/keyrings/migration_set_commitment_policy_example.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
This example configures a client with a specific commitment policy for the
55
AWS Encryption SDK client, then encrypts and decrypts data using an AWS KMS Keyring.
66
7-
The commitment policy in this example (FORBID_ENCRYPT_ALLOW_DECRYPT) should only be used as part
8-
of a migration from version 1.x to 2.x, or for advanced users with specialized requirements.
9-
We recommend that AWS Encryption SDK users use the default commitment policy
10-
(REQUIRE_ENCRYPT_REQUIRE_DECRYPT) whenever possible.
7+
The commitment policy in this example (FORBID_ENCRYPT_ALLOW_DECRYPT) should only be
8+
used as part of a migration from version 1.x to 2.x, or for advanced users with
9+
specialized requirements. Most AWS Encryption SDK users should use the default
10+
commitment policy (REQUIRE_ENCRYPT_REQUIRE_DECRYPT).
1111
1212
This example creates a KMS Keyring and then encrypts a custom input EXAMPLE_DATA
1313
with an encryption context for the commitment policy FORBID_ENCRYPT_ALLOW_DECRYPT.

examples/src/keyrings/set_encryption_algorithm_example.py

+19-12
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,28 @@
44
This example demonstrates how to set an encryption algorithm while using the Raw AES Keyring
55
in the AWS Encryption SDK.
66
7+
The encryption algorithm used in the encrypt() method is the algorithm used to protect your
8+
data using the data key. By setting this algorithm, you can configure the algorithm used
9+
to encrypt and decrypt your data.
10+
711
Encryption algorithms can be set in a similar manner in other keyrings as well. However,
812
please make sure that you're using a logical encryption algorithm that is compatible with your
9-
keyring. For example, AWS KMS RSA Keyring does not support use with an algorithm suite
10-
containing an asymmetric signature.
11-
12-
The Raw AES keyring encrypts data by using the AES-GCM algorithm and a wrapping key that
13-
you specify as a byte array. You can specify only one wrapping key in each Raw AES keyring,
14-
but you can include multiple Raw AES keyrings, alone or with other keyrings, in a multi-keyring.
13+
keyring. For more information on encryption algorithms supported by the AWS Encryption SDK, see
14+
https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/supported-algorithms.html
1515
1616
The AES wrapping algorithm (AesWrappingAlg.ALG_AES256_GCM_IV12_TAG16) protects your data key using
1717
the user-provided wrapping key. The encryption algorithm used in the encrypt() method is the
1818
algorithm used to protect your data using the data key. This example demonstrates setting the
19-
latter, which is the encryption algorithm for protecting your data. The default algorithm used
20-
in encrypt method is AES_256_GCM_HKDF_SHA512_COMMIT_KEY_ECDSA_P384 when the commitment policy is
21-
REQUIRE_ENCRYPT_REQUIRE_DECRYPT which is a committing and signing algorithm. This example sets
22-
the encryption algorithm as AES_256_GCM_HKDF_SHA512_COMMIT_KEY which is a committing but
23-
non-signing algorithm.
19+
latter, which is the encryption algorithm for protecting your data. When the commitment policy is
20+
REQUIRE_ENCRYPT_REQUIRE_DECRYPT, the default algorithm used in the encrypt method is
21+
AES_256_GCM_HKDF_SHA512_COMMIT_KEY_ECDSA_P384, which is a committing and signing algorithm.
22+
Signature verification is extremely useful to ensure the integrity of a digital message as it
23+
goes between systems. However, signature verification adds a significant performance cost on
24+
decryption. If the users encrypting data and the users decrypting data are equally trusted, we can
25+
consider using an algorithm suite that does not include signing. This example sets the encryption
26+
algorithm as AES_256_GCM_HKDF_SHA512_COMMIT_KEY which is a committing but non-signing algorithm.
27+
For more information on digital signatures, see
28+
https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/concepts.html#digital-sigs
2429
2530
This example creates a Raw AES Keyring and then encrypts a custom input EXAMPLE_DATA
2631
with an encryption context and the encryption algorithm AES_256_GCM_HKDF_SHA512_COMMIT_KEY.
@@ -101,6 +106,7 @@ def encrypt_and_decrypt_with_keyring():
101106
config=MaterialProvidersConfig()
102107
)
103108

109+
# The wrapping algorithm here is NOT the encryption algorithm we set in this example.
104110
keyring_input: CreateRawAesKeyringInput = CreateRawAesKeyringInput(
105111
key_namespace=key_name_space,
106112
key_name=key_name,
@@ -113,7 +119,8 @@ def encrypt_and_decrypt_with_keyring():
113119
)
114120

115121
# 6. Encrypt the data with the encryptionContext.
116-
# Specify the encryption algorithm you want to use for encrypting your data here
122+
# This is the important step in this example where we specify the encryption algorithm
123+
# you want to use for encrypting your data here
117124
ciphertext, _ = client.encrypt(
118125
source=EXAMPLE_DATA,
119126
keyring=raw_aes_keyring,

0 commit comments

Comments
 (0)