AWS签名不正确

时间:2019-01-08 05:33:16

标签: java android amazon-web-services aws-sdk

我正在尝试获取以下代码的签名,但是得到的结果不正确。当UTC时间为 20190108T053505Z 时,我得到以下结果:

  

AWS4-HMAC-SHA256凭据= TEST_ACCESS_KEY / 20190108 / us-east-1 / iotdata / aws4_request,SignedHeaders = host; x-amz-date ,SignatureHeaders = e797617c297b6ae2bed4fb9a5ae3b85b183d7ad64d >

如何使签名正常工作?

public class MainActivity extends AppCompatActivity {
public static TextView data;

private AWS4Signer signer = new AWS4Signer();
Request<?> aws;

String AccessKey = "TEST_ACCESS_KEY";
String SecretKey = "TEST_SECRET_KEY";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    data = (TextView) findViewById(R.id.fetchdata);

    AWSCredentials credentials = new BasicAWSCredentials(AccessKey, SecretKey);
    aws = generateBasicRequest();

    signer.setRegionName("us-east-1");
    signer.setServiceName("iotdata");
    signer.sign(aws, credentials);

    String test = aws.getHeaders().get("X-Amz-Date") + "\n\n" + aws.getHeaders().get("Authorization");

    MainActivity.data.setText(test);
    }

    private Request<?> generateBasicRequest() {
    Request<?> request = new DefaultRequest<Void>("iotdata");

    Map<String, String> map = new HashMap<String, String>();
    map.put("Content-Type", "application/x-www-form-urlencoded");

    request.setHeaders(map);
    request.setResourcePath("/");
    request.setEndpoint(URI.create("https://a37j7zivprtjq5.iot.us-east-1.amazonaws.com/things/thermostat/shadow"));
    request.setHttpMethod(HttpMethodName.GET);
    return request;
    }
}

我应该在UTC时间得到的正确结果是:

  

AWS4-HMAC-SHA256凭据= TEST_ACCESS_KEY / 20190108 / us-east-1 / iotdata / aws4_request,SignedHeaders = content-type; host; x-amz-date ,签名= f39ccc92a8d60450ceceb32d3bba42fdb06120598d34c5f4f87299abd3d92fb4

0 个答案:

没有答案