Skip to content

Commit 9d29529

Browse files
Chris Chonlarew
authored andcommitted
DOCSP-6486: add local master key section content
1 parent dc2375b commit 9d29529

File tree

1 file changed

+44
-7
lines changed

1 file changed

+44
-7
lines changed

source/use-cases/sensitive-data-encryption.txt

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,52 @@ Requirements
4444
- Nullam imperdiet lorem vitae vulputate lacinia.
4545
- Donec eget velit tincidunt, gravida diam ac, efficitur lacus.
4646

47-
A. Create a Local Master Key
47+
A. Create a Master Key
4848
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4949

50-
Aenean eu consequat lorem. Ut posuere est sed sodales pharetra. Cras
51-
volutpat, massa laoreet varius dictum, leo odio porttitor ante, nec
52-
auctor tortor orci et mi. Maecenas tempor, lacus vehicula molestie
53-
pulvinar, ante eros faucibus odio, sed consequat quam tellus vel arcu.
54-
Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere
55-
cubilia Curae; Nunc non interdum purus, ultricies laoreet tortor.
50+
MongoDB `Client-Side Field Level Encryption (CSFLE) <https://docs.mongodb.com/manual/core/security-client-side-encryption/>`_ uses an encryption strategy called *envelope encryption* in which keys used to encrypt/decrypt data (called **data encryption keys**) are encrypted with another key (called the **master key**). For more information on the features of envelope encryption and key management concepts, see `AWS Key Management Service Concepts <https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#enveloping>`_.
51+
52+
The master key, used by the MongoDB driver to create and encrypt data keys, should be stored remotely in a `Key Management System <https://en.wikipedia.org/wiki/Key_management#Key_management_system>`_. The data encryption keys, generated and used by the MongoDB driver to encrypt and decrypt document fields, are stored in a key vault collection in the same database as the encrypted data.
53+
54+
In this step, we generate a local master key to expedite setup of our development environment.
55+
56+
.. admonition:: Local Master Keys Are Not Secure
57+
:class: important
58+
59+
To ensure that the master key cannot be compromised, do not use a local master key in a production environment. Instead, use a secure KMS such as `AWS KMS <https://aws.amazon.com/kms/>`_.
60+
61+
We demonstrate how to transition from a locally-hosted master key to a remote AWS KMS master key in a later step of this guide.
62+
63+
.. tabs::
64+
65+
tabs:
66+
67+
- id: java-master-key-generator
68+
name: "Java"
69+
content: |
70+
71+
The following script generates a 96-byte local master key and saves it to a file called ``master-key.txt`` in the directory from which the script is executed.
72+
73+
.. code-block:: java
74+
75+
import java.io.FileOutputStream;
76+
import java.io.IOException;
77+
import java.security.SecureRandom;
78+
79+
public class CreateMasterKeyFile {
80+
public static void main(final String[] args) {
81+
82+
final byte[] localMasterKey = new byte[96];
83+
new SecureRandom().nextBytes(localMasterKey);
84+
85+
try (FileOutputStream stream = new FileOutputStream("master-key.txt")) {
86+
stream.write(localMasterKey);
87+
} catch (IOException e) {
88+
e.printStackTrace();
89+
}
90+
}
91+
}
92+
5693

5794
B. Define a JSON Schema
5895
~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)