Advertisement
Guest User

Untitled

a guest
Oct 5th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. from barbicanclient import client
  2. import base64
  3. from keystoneauth1.identity import v2
  4. from keystoneauth1 import session
  5. import os
  6.  
  7. _AES_256_SIZE=32 # bytes
  8. AES_256_KEY = os.urandom(_AES_256_SIZE)
  9.  
  10. auth = v2.Password(username=os.environ['OS_USERNAME'],
  11. password=os.environ['OS_PASSWORD'],
  12. auth_url=os.environ['OS_AUTH_URL'])
  13. sess = session.Session(auth=auth)
  14. barbican = client.Client(session=sess)
  15. key = barbican.secrets.create(secret_type='symmetric',
  16. payload=base64.b64encode(AES_256_KEY).decode('UTF-8'),
  17. payload_content_type='application/octet-stream',
  18. payload_content_encoding='base64')
  19. key.store()
  20. # At this point you should persist KEY_REF somewhere so you can retrieve the key later.
  21. KEY_REF = key.secret_ref
  22.  
  23. # Later, when you wan to retrieve the key for usage do this
  24. retrieved_key = barbican.secrets.get(KEY_REF)
  25. key_bytes = retrieved_key.payload
  26.  
  27. # You should get the same original key that was stored
  28. assert AES_256_KEY == key_bytes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement