Skip to content

Instantly share code, notes, and snippets.

@paulegan
Created October 20, 2015 15:08
Show Gist options
  • Save paulegan/c0a45134d032718d729b to your computer and use it in GitHub Desktop.
Save paulegan/c0a45134d032718d729b to your computer and use it in GitHub Desktop.
Example of decrypting configuration variables in Python settings file
import os
try:
from Crypto.Cipher import AES as aes
key, iv = os.environ['SETTINGS_KEY'].split(':')
except (ImportError, KeyError):
def _decrypt(s):
return s
else:
def _decrypt(s):
_aes = aes.new(key, aes.MODE_CFB, iv)
return _aes.decrypt(s)
DEBUG = False
FOO = 'bar'
SECRET_KEY = _decrypt('\xc6\xcau\x06\xbe\x80W\xe6\xee\x96M\xb7\xc7\xc4d\xdc$H\x84\xb6\x8f\xd6\x10\x9b-\n\xce\x14\x85\xca\xf0R')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment