groovy - Base64Encode for AWS not matching Amazon Example -


i seem failing @ first hurdle in quest amazon s3 browser-based uploads.

using amazon's example shown here : http://docs.aws.amazon.com/amazons3/latest/api/sigv4-post-example.html

using groovy/java, i'm unable encode example post policy , produce same encoding amazon.

{ "expiration": "2015-12-30t12:00:00.000z",   "conditions": [     {"bucket": "sigv4examplebucket"},     ["starts-with", "$key", "user/user1/"],     {"acl": "public-read"},     {"success_action_redirect": "http://sigv4examplebucket.s3.amazonaws.com/successful_upload.html"},     ["starts-with", "$content-type", "image/"],     {"x-amz-meta-uuid": "14365123651274"},     {"x-amz-server-side-encryption": "aes256"},     ["starts-with", "$x-amz-meta-tag", ""],      {"x-amz-credential": "akiaiosfodnn7example/20151229/us-east-1/s3/aws4_request"},     {"x-amz-algorithm": "aws4-hmac-sha256"},     {"x-amz-date": "20151229t000000z" }   ] } 

i have defined groovy multi line string:

string policy_document = ''' { "expiration": "2015-12-30t12:00:00.000z",   "conditions": [     {"bucket": "sigv4examplebucket"},     ["starts-with", "$key", "user/user1/"],     {"acl": "public-read"},     {"success_action_redirect": "http://sigv4examplebucket.s3.amazonaws.com/successful_upload.html"},     ["starts-with", "$content-type", "image/"],     {"x-amz-meta-uuid": "14365123651274"},     {"x-amz-server-side-encryption": "aes256"},     ["starts-with", "$x-amz-meta-tag", ""],      {"x-amz-credential": "akiaiosfodnn7example/20151229/us-east-1/s3/aws4_request"},     {"x-amz-algorithm": "aws4-hmac-sha256"},     {"x-amz-date": "20151229t000000z" }   ] } ''' 

i'm encoding , verifying assert fails.

string base64policy = (new base64encoder()).encode(policy_document.replaceall("\n", "").replaceall("\r", "").getbytes("utf-8")) assert 'eyaizxhwaxjhdglvbii6iciymde1lteyltmwvdeyojawojawljawmfoila0kicaiy29uzgl0aw9ucyi6ifsnciagicb7imj1y2tldci6icjzawd2ngv4yw1wbgvidwnrzxqifswnciagicbbinn0yxj0cy13axroiiwgiirrzxkilcaidxnlci91c2vyms8ixswnciagicb7imfjbci6icjwdwjsawmtcmvhzcj9la0kicagihsic3vjy2vzc19hy3rpb25fcmvkaxjly3qioiaiahr0cdovl3npz3y0zxhhbxbszwj1y2tldc5zmy5hbwf6b25hd3muy29tl3n1y2nlc3nmdwxfdxbsb2fklmh0bwwifswnciagicbbinn0yxj0cy13axroiiwgiirdb250zw50lvr5cguilcaiaw1hz2uvil0sdqogicageyj4lwftei1tzxrhlxv1awqioiaimtqznjuxmjm2nteynzqifswnciagicb7ingtyw16lxnlcnzlci1zawrllwvuy3j5chrpb24ioiaiquvtmju2in0sdqogicagwyjzdgfydhmtd2l0acisicikec1hbxotbwv0ys10ywcilcaiil0sdqonciagicb7ingtyw16lwnyzwrlbnrpywwioiaiqutjqulpu0zpre5on0vyqu1qteuvmjaxnteymjkvdxmtzwfzdc0xl3mzl2f3czrfcmvxdwvzdcj9la0kicagihsiec1hbxotywxnb3jpdghtijogikfxuzqtse1bqy1tseeyntyifswnciagicb7ingtyw16lwrhdguioiaimjaxnteymjlumdawmdawwiigfq0kicbddqp9' == base64policy 

just readability, when encode :

eyaizxhwaxjhdglvbii6iciymde1lteyltmwvdeyojawojawljawmfoilcagimnvbmrpdglvbnmioibbicagihsiynvja2v0ijoginnpz3y0zxhhbxbszwj1y2tldcj9lcagicbbinn0yxj0cy13axroiiwgiirrzxkilcaidxnlci91c2vyms8ixswgicageyjhy2wioiaichvibgljlxjlywqifswgicageyjzdwnjzxnzx2fjdglvbl9yzwrpcmvjdci6icjodhrwoi8vc2lndjrlegftcgxlynvja2v0lnmzlmftyxpvbmf3cy5jb20vc3vjy2vzc2z1bf91cgxvywquahrtbcj9lcagicbbinn0yxj0cy13axroiiwgiirdb250zw50lvr5cguilcaiaw1hz2uvil0sicagihsiec1hbxotbwv0ys11dwlkijogije0mzy1mtiznjuxmjc0in0sicagihsiec1hbxotc2vydmvylxnpzgutzw5jcnlwdglvbii6icjbrvmyntyifswgicagwyjzdgfydhmtd2l0acisicikec1hbxotbwv0ys10ywcilcaiil0sicagihsiec1hbxoty3jlzgvudglhbci6icjbs0lbsu9trk9etk43rvhbtvbmrs8ymde1mtiyos91cy1lyxn0ltevczmvyxdznf9yzxf1zxn0in0sicagihsiec1hbxotywxnb3jpdghtijogikfxuzqtse1bqy1tseeyntyifswgicageyj4lwftei1kyxrlijogijiwmtuxmji5vdawmdawmfoiih0gif19

but should getting :

eyaizxhwaxjhdglvbii6iciymde1lteyltmwvdeyojawojawljawmfoila0kicaiy29uzgl0aw9ucyi6ifsnciagicb7imj1y2tldci6icjzawd2ngv4yw1wbgvidwnrzxqifswnciagicbbinn0yxj0cy13axroiiwgiirrzxkilcaidxnlci91c2vyms8ixswnciagicb7imfjbci6icjwdwjsawmtcmvhzcj9la0kicagihsic3vjy2vzc19hy3rpb25fcmvkaxjly3qioiaiahr0cdovl3npz3y0zxhhbxbszwj1y2tldc5zmy5hbwf6b25hd3muy29tl3n1y2nlc3nmdwxfdxbsb2fklmh0bwwifswnciagicbbinn0yxj0cy13axroiiwgiirdb250zw50lvr5cguilcaiaw1hz2uvil0sdqogicageyj4lwftei1tzxrhlxv1awqioiaimtqznjuxmjm2nteynzqifswnciagicb7ingtyw16lxnlcnzlci1zawrllwvuy3j5chrpb24ioiaiquvtmju2in0sdqogicagwyjzdgfydhmtd2l0acisicikec1hbxotbwv0ys10ywcilcaiil0sdqonciagicb7ingtyw16lwnyzwrlbnrpywwioiaiqutjqulpu0zpre5on0vyqu1qteuvmjaxnteymjkvdxmtzwfzdc0xl3mzl2f3czrfcmvxdwvzdcj9la0kicagihsiec1hbxotywxnb3jpdghtijogikfxuzqtse1bqy1tseeyntyifswnciagicb7ingtyw16lwrhdguioiaimjaxnteymjlumdawmdawwiigfq0kicbddqp9

i'm hoping fresh set of eyes point me in direction. many advice can offered.

the following worked me in java. leave carriage return , line feeds in place.

string policy_document = "{ \"expiration\": \"2015-12-30t12:00:00.000z\",\n" +             "  \"conditions\": [\n" +             "    {\"bucket\": \"sigv4examplebucket\"},\n" +             "    [\"starts-with\", \"$key\", \"user/user1/\"],\n" +             "    {\"acl\": \"public-read\"},\n" +             "    {\"success_action_redirect\": \"http://sigv4examplebucket.s3.amazonaws.com/successful_upload.html\"},\n" +             "    [\"starts-with\", \"$content-type\", \"image/\"],\n" +             "    {\"x-amz-meta-uuid\": \"14365123651274\"},\n" +             "    {\"x-amz-server-side-encryption\": \"aes256\"},\n" +             "    [\"starts-with\", \"$x-amz-meta-tag\", \"\"],\n" +             "\n" +             "    {\"x-amz-credential\": \"akiaiosfodnn7example/20151229/us-east-1/s3/aws4_request\"},\n" +             "    {\"x-amz-algorithm\": \"aws4-hmac-sha256\"},\n" +             "    {\"x-amz-date\": \"20151229t000000z\" }\n" +             "  ]\n" +             "}";     string base64policy = (new base64encoder()).encode(policy_document.getbytes()); 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -