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: source/use-cases/sensitive-data-encryption.txt
+44-7Lines changed: 44 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -44,15 +44,52 @@ Requirements
44
44
- Nullam imperdiet lorem vitae vulputate lacinia.
45
45
- Donec eget velit tincidunt, gravida diam ac, efficitur lacus.
46
46
47
-
A. Create a Local Master Key
47
+
A. Create a Master Key
48
48
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
49
49
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")) {
0 commit comments