Skip to content

Instantly share code, notes, and snippets.

@stephenhowells
Created September 26, 2013 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephenhowells/6718627 to your computer and use it in GitHub Desktop.
Save stephenhowells/6718627 to your computer and use it in GitHub Desktop.
Python Script to generate a policy and signature. Useful when using CORS uploads to S3.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import base64, hmac, sha
private_key = 'YOUR PRIVATE KEY'
input = open("policy.txt", "rb")
policy = input.read()
policy_encoded = base64.b64encode(policy)
signature = base64.b64encode(hmac.new(private_key, policy_encoded, sha).digest())
print "Your policy base-64 encoded is %s." % (policy_encoded)
print "Your signature base-64 encoded is %s." % (signature)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment