Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think this is down to the contents of your policy.txt file.</p> <p>I took the policy from the referenced link (<a href="http://doc.s3.amazonaws.com/proposals/post.html" rel="noreferrer">http://doc.s3.amazonaws.com/proposals/post.html</a>) and saved it as policy.txt</p> <pre><code>{ "expiration": "2007-12-01T12:00:00.000Z", "conditions": [ {"bucket": "johnsmith" }, ["starts-with", "$key", "user/eric/"], {"acl": "public-read" }, {"redirect": "http://johnsmith.s3.amazonaws.com/successful_upload.html" }, ["starts-with", "$Content-Type", "image/"], {"x-amz-meta-uuid": "14365123651274"}, ["starts-with", "$x-amz-meta-tag", ""], ] } </code></pre> <p>In order to get the exact same signature, this file must have the exact same contents.</p> <p>For reference, when I copied and pasted: MD5 (policy.txt) = 5bce89d9ff799e2064c136d76bc7fc7a</p> <p>If I use the following script (same as yours, just adjust filename and remove <code>args</code>)</p> <pre><code>#!/usr/bin/env python # -*- coding: utf-8 -*- import base64, hmac, sha private_key = 'uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o' 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) print "Your signature encoded should be 2qCp0odXe7A9IYyUVqn0w2adtCA=" </code></pre> <p>Output I get:</p> <pre> Your policy base-64 encoded is eyAiZXhwaXJhdGlvbiI6ICIyMDA3LTEyLTAxVDEyOjAwOjAwLjAwMFoiLAogICJjb25kaXRpb25zIjo gWwogICAgeyJidWNrZXQiOiAiam9obnNtaXRoIiB9LAogICAgWyJzdGFydHMtd2l0aCIsICIka2V5Ii wgInVzZXIvZXJpYy8iXSwKICAgIHsiYWNsIjogInB1YmxpYy1yZWFkIiB9LAogICAgeyJyZWRpcmVjd CI6ICJodHRwOi8vam9obnNtaXRoLnMzLmFtYXpvbmF3cy5jb20vc3VjY2Vzc2Z1bF91cGxvYWQuaHRt bCIgfSwKICAgIFsic3RhcnRzLXdpdGgiLCAiJENvbnRlbnQtVHlwZSIsICJpbWFnZS8iXSwKICAgIHs ieC1hbXotbWV0YS11dWlkIjogIjE0MzY1MTIzNjUxMjc0In0sCiAgICBbInN0YXJ0cy13aXRoIiwgIi R4LWFtei1tZXRhLXRhZyIsICIiXSwKICBdCn0K Your signature base-64 encoded is 2qCp0odXe7A9IYyUVqn0w2adtCA= Your signature encoded should be 2qCp0odXe7A9IYyUVqn0w2adtCA= </pre> <p>So, your code works, I just think you're signing a slightly different policy (whitespace differences)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload