52
52
"the data you are handling" : "is what you think it is" ,
53
53
}
54
54
55
+ # The key namespace in the Raw keyrings is equivalent to Provider ID (or Provider) field
56
+ # in the Raw Master Key Providers
55
57
DEFAULT_KEY_NAME_SPACE = "Some managed raw keys"
56
58
59
+ # The key name in the Raw keyrings is equivalent to the Key ID field
60
+ # in the Raw Master Key Providers
57
61
DEFAULT_KEY_NAME = "My 4096-bit RSA wrapping key"
58
62
59
63
@@ -98,6 +102,10 @@ def create_keyring(public_key, private_key):
98
102
config = MaterialProvidersConfig ()
99
103
)
100
104
105
+ # The key namespace in the Raw keyrings is equivalent to Provider ID (or Provider) field
106
+ # in the Raw Master Key Providers
107
+ # The key name in the Raw keyrings is equivalent to the Key ID field
108
+ # in the Raw Master Key Providers
101
109
keyring_input : CreateRawRsaKeyringInput = CreateRawRsaKeyringInput (
102
110
key_namespace = DEFAULT_KEY_NAME_SPACE ,
103
111
key_name = DEFAULT_KEY_NAME ,
@@ -114,24 +122,24 @@ def create_keyring(public_key, private_key):
114
122
115
123
116
124
# This is a helper class necessary for the Raw RSA master key provider.
117
- # In the StaticRandomMasterKeyProvider , we fix the static key to
125
+ # In the StaticMasterKeyProvider , we fix the static key to
118
126
# DEFAULT_RSA_PRIVATE_KEY in order to make the test deterministic.
119
127
# Thus, both the Raw RSA keyring and Raw RSA MKP have the same private_key
120
128
# and we are able to encrypt data using keyrings and decrypt using MKP and vice versa
121
- # In practice, users should generate a new key pair for each key id.
122
- class StaticRandomMasterKeyProvider (RawMasterKeyProvider ):
123
- """Randomly generates and provides 4096-bit RSA keys consistently per unique key id."""
129
+ # In practice, users should generate a new random key pair for each key id.
130
+ class StaticMasterKeyProvider (RawMasterKeyProvider ):
131
+ """Provides 4096-bit RSA keys consistently per unique key id."""
124
132
125
- # The Provider ID (or Provider) field in the JceMasterKey and RawMasterKey is
126
- # equivalent to key namespace in the Raw keyrings
133
+ # The key namespace in the Raw keyrings is equivalent to Provider ID (or Provider) field
134
+ # in the Raw Master Key Providers
127
135
provider_id = DEFAULT_KEY_NAME_SPACE
128
136
129
137
def __init__ (self , ** kwargs ): # pylint: disable=unused-argument
130
138
"""Initialize empty map of keys."""
131
139
self ._static_keys = {}
132
140
133
141
def _get_raw_key (self , key_id ):
134
- """Retrieves a static, randomly generated, RSA key for the specified key id.
142
+ """Retrieves a static, RSA key for the specified key id.
135
143
136
144
:param str key_id: User-defined ID for the static key
137
145
:returns: Wrapping key that contains the specified static key
@@ -143,7 +151,7 @@ def _get_raw_key(self, key_id):
143
151
# We fix the static key in order to make the test deterministic
144
152
# In practice, you should get this key from a secure key management system such as an HSM.
145
153
# Also, in practice, users should generate a new key pair for each key id in
146
- # the StaticRandomMasterKeyProvider .
154
+ # the StaticMasterKeyProvider .
147
155
static_key = DEFAULT_RSA_PRIVATE_KEY
148
156
self ._static_keys [key_id ] = static_key
149
157
return WrappingKey (
@@ -160,17 +168,17 @@ def create_key_provider():
160
168
"""
161
169
# Create a Raw RSA master key provider.
162
170
163
- # The Key ID field in the JceMasterKey and RawMasterKey is equivalent to key name
164
- # in the Raw keyrings
171
+ # The key name in the Raw keyrings is equivalent to the Key ID field
172
+ # in the Raw Master Key Providers
165
173
key_id = DEFAULT_KEY_NAME
166
174
167
175
# In this example, we fix the static key to DEFAULT_RSA_PRIVATE_KEY in both the keyring
168
- # and MKP (for MKP, we fix the static key in StaticRandomMasterKeyProvider ) in order to make
176
+ # and MKP (for MKP, we fix the static key in StaticMasterKeyProvider ) in order to make
169
177
# the test deterministic. Thus, both the Raw RSA keyring and Raw RSA MKP have the same
170
178
# private_key and we are able to encrypt data using keyrings and decrypt using MKP
171
179
# and vice versa. In practice, users should generate a new key pair for each key id in
172
- # the StaticRandomMasterKeyProvider .
173
- key_provider = StaticRandomMasterKeyProvider ()
180
+ # the StaticMasterKeyProvider .
181
+ key_provider = StaticMasterKeyProvider ()
174
182
key_provider .add_master_key (key_id )
175
183
176
184
return key_provider
@@ -192,11 +200,11 @@ def migration_raw_rsa_key(
192
200
# 1b. Create a Raw RSA Master Key Provider
193
201
194
202
# In this example, we fix the static key to DEFAULT_RSA_PRIVATE_KEY in both the keyring
195
- # and MKP (for MKP, we fix the static key in StaticRandomMasterKeyProvider ) in order to make
203
+ # and MKP (for MKP, we fix the static key in StaticMasterKeyProvider ) in order to make
196
204
# the test deterministic. Thus, both the Raw RSA keyring and Raw RSA MKP have the same
197
205
# private_key and we are able to encrypt data using keyrings and decrypt using MKP
198
206
# and vice versa. In practice, users should generate a new key pair for each key id in
199
- # the StaticRandomMasterKeyProvider .
207
+ # the StaticMasterKeyProvider .
200
208
raw_rsa_master_key_provider = create_key_provider ()
201
209
202
210
# 2a. Encrypt EXAMPLE_DATA using Raw RSA Keyring
0 commit comments