MCPcopy Create free account
hub / github.com/StackStorm/st2 / read_crypto_key

Function read_crypto_key

st2common/st2common/util/crypto.py:183–209  ·  view source on GitHub ↗

Read crypto key from keyczar JSON key file format and return parsed AESKey object. :param key_path: Absolute path to file containing crypto key in Keyczar JSON format. :type key_path: ``str`` :rtype: :class:`AESKey`

(key_path)

Source from the content-addressed store, hash-verified

181
182
183def read_crypto_key(key_path):
184 """
185 Read crypto key from keyczar JSON key file format and return parsed AESKey object.
186
187 :param key_path: Absolute path to file containing crypto key in Keyczar JSON format.
188 :type key_path: ``str``
189
190 :rtype: :class:`AESKey`
191 """
192 with open(key_path, "r") as fp:
193 content = fp.read()
194
195 content = json_decode(content)
196
197 try:
198 aes_key = AESKey(
199 aes_key_string=content["aesKeyString"],
200 hmac_key_string=content["hmacKey"]["hmacKeyString"],
201 hmac_key_size=content["hmacKey"]["size"],
202 mode=content["mode"].upper(),
203 size=content["size"],
204 )
205 except KeyError as e:
206 msg = 'Invalid or malformed key file "%s": %s' % (key_path, six.text_type(e))
207 raise KeyError(msg)
208
209 return aes_key
210
211
212def symmetric_encrypt(encrypt_key, plaintext):

Callers 4

setUpMethod · 0.90
decrypt_kvFunction · 0.90
_setup_cryptoMethod · 0.90

Calls 3

json_decodeFunction · 0.90
AESKeyClass · 0.85
readMethod · 0.45

Tested by 2

setUpMethod · 0.72