How do I create and validate a signature using the EventStreamAws4Signer class from the SNS Java SDK?

0

I've asked ChatGPT to give me an example on how to do this, it came up with the following:

    public void publishMessage(String topicArn, String message) {
        SnsClient snsClient = SnsClient.builder()
                .region(Region.US_WEST_2)
                .credentialsProvider(EnvironmentVariableCredentialsProvider.create())
                .build();

        PublishRequest publishRequest = PublishRequest.builder()
                .topicArn(topicArn)
                .message(message)
                .build();

        EventStreamAws4Signer signer = EventStreamAws4Signer.builder()
                .credentialsProvider(EnvironmentVariableCredentialsProvider.create())
                .build();

        SdkBytes payload = SdkBytes.fromByteArray(message.getBytes());

        String signature = signer.sign(publishRequest, payload).get("signature");

        snsClient.publish(builder -> builder
                .message(message)
                .topicArn(topicArn)
                .signature(signature)
                .build());
    }

In reality EventStreamAws4Signer doesn't have a builder() method, only a create() method. But the latter method doesn't provide a way to configure the access keys or use the instance profile access keys for signing.

How do I use the EventStreamAws4Signer to get a signature? I've looked at the code examples in the docs here: https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/java_sns_code_examples.html and also in the code examples on github here: https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javav2/example_code/sns/src/main/java/com/example/sns

But couldn't find what i was looking for. I need to know how I can both create a signature and how to validate a signature. Thank you

질문됨 일 년 전271회 조회
1개 답변
0
  • this is not helpful. I need to know how to create my own signature string and how to verify signature strings extracted from the headers of other SNS notifications

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠