|
| 1 | +# AWS Encryption SDK Examples |
| 2 | + |
| 3 | +This section features examples that show you |
| 4 | +how to use the AWS Encryption SDK. |
| 5 | +We demonstrate how to use the encryption and decryption APIs |
| 6 | +and how to set up some common configuration patterns. |
| 7 | + |
| 8 | +## APIs |
| 9 | + |
| 10 | +The AWS Encryption SDK provides two high-level APIs: |
| 11 | +one-step APIs that process the entire operation in memory |
| 12 | +and streaming APIs. |
| 13 | + |
| 14 | +You can find examples that demonstrate these APIs |
| 15 | +in the [`examples/src/`](./src) directory. |
| 16 | + |
| 17 | +## Configuration |
| 18 | + |
| 19 | +To use the library APIs, |
| 20 | +you need to describe how you want the library to protect your data keys. |
| 21 | +You can do this using |
| 22 | +[keyrings][#keyrings] or [cryptographic materials managers][#cryptographic-materials-managers], |
| 23 | +or using [master key providers][#master-key-providers]. |
| 24 | +These examples will show you how. |
| 25 | + |
| 26 | +### Keyrings |
| 27 | + |
| 28 | +Keyrings are the most common way for you to configure the AWS Encryption SDK. |
| 29 | +They determine how the AWS Encryption SDK protects your data. |
| 30 | +You can find these examples in [`examples/src/keyring`](./src/keyring). |
| 31 | + |
| 32 | +### Cryptographic Materials Managers |
| 33 | + |
| 34 | +Keyrings define how your data keys are protected, |
| 35 | +but there is more going on here than just protecting data keys. |
| 36 | + |
| 37 | +Cryptographic materials managers give you higher-level controls |
| 38 | +over how the AWS Encryption SDK protects your data. |
| 39 | +This can include things like |
| 40 | +enforcing the use of certain algorithm suites or encryption context settings, |
| 41 | +reusing data keys across messages, |
| 42 | +or changing how you interact with keyrings. |
| 43 | +You can find these examples in |
| 44 | +[`examples/src/crypto_materials_manager`](./src/crypto_materials_manager). |
| 45 | + |
| 46 | +### Master Key Providers |
| 47 | + |
| 48 | +Before there were keyrings, there were master key providers. |
| 49 | +Master key providers were the original configuration structure |
| 50 | +that we provided for defining how you want to protect your data keys. |
| 51 | +Keyrings provide a simpler experience and often more powerful configuration options, |
| 52 | +but if you need to use master key providers, |
| 53 | +need help migrating from master key providers to keyrings, |
| 54 | +or simply want to see the difference between these configuration experiences, |
| 55 | +you can find these examples in [`examples/src/master_key_provider`](./src/master_key_provider). |
| 56 | + |
| 57 | +## Legacy |
| 58 | + |
| 59 | +This section includes older examples, including examples of using master keys and master key providers in Java and Python. |
| 60 | +You can use them as a reference, |
| 61 | +but we recommend looking at the newer examples, which explain the preferred ways of using this library. |
| 62 | +You can find these examples in [`examples/src/legacy`](./src/legacy). |
| 63 | + |
| 64 | +# Writing Examples |
| 65 | + |
| 66 | +If you want to contribute a new example, that's awesome! |
| 67 | +To make sure that your example is tested in our CI, |
| 68 | +please make sure that it meets the following requirements: |
| 69 | + |
| 70 | +1. The example MUST be a distinct module in the [`examples/src/`](./src) directory. |
| 71 | +1. The example MAY be nested arbitrarily deeply, |
| 72 | + but every intermediate directory MUST contain a `__init__.py` file |
| 73 | + so that CPython 2.7 will recognize it as a module. |
| 74 | +1. Every example MUST be CPython 2.7 compatible. |
| 75 | +1. Each example file MUST contain exactly one example. |
| 76 | +1. Each example file MUST contain a function called `run` that runs the example. |
| 77 | +1. If your `run` function needs any of the following inputs, |
| 78 | + the parameters MUST have the following names: |
| 79 | + * `aws_kms_cmk` (`str`) : A single AWS KMS CMK ARN. |
| 80 | + * NOTE: You can assume that automatically discovered credentials have |
| 81 | + `kms:GenerateDataKey`, `kms:Encrypt`, and `kms:Decrypt` permissions on this CMK. |
| 82 | + * `aws_kms_generator_cmk` (`str`) : A single AWS KMS CMK ARN to use as a generator key. |
| 83 | + * NOTE: You can assume that automatically discovered credentials have |
| 84 | + `kms:GenerateDataKey`, `kms:Encrypt`, and `kms:Decrypt` permissions on this CMK. |
| 85 | + * `aws_kms_additional_cmks` (`List[str]`) : |
| 86 | + A list of AWS KMS CMK ARNs to use for encrypting and decrypting data keys. |
| 87 | + * NOTE: You can assume that automatically discovered credentials have |
| 88 | + `kms:Encrypt` and `kms:Decrypt` permissions on these CMKs. |
| 89 | + * `source_plaintext` (`bytes`) : Plaintext data to encrypt. |
| 90 | + * `source_plaintext_filename` (`str`) : A path to a file containing plaintext to encrypt. |
| 91 | + * NOTE: You can assume that you have write access to the parent directory |
| 92 | + and that anything you do in that directory will be cleaned up |
| 93 | + by our test runners. |
| 94 | +1. Any additional parameters MUST be optional. |
0 commit comments