java.lang.Object
software.amazon.awssdk.http.auth.aws.internal.signer.util.SignerUtils

public final class SignerUtils extends Object
Utility methods to be used by various AWS Signer implementations. This class is protected and subject to change.
  • Method Details

    • formatDate

      public static String formatDate(Instant instant)
      Returns a string representation of the given datetime in yyyyMMdd format. The date returned is in the UTC zone.

      For example, given an Instant with millis-value of 1416863450581, this method returns "20141124"

    • formatDateTime

      public static String formatDateTime(Instant instant)
      Returns a string representation of the given datetime in yyyyMMdd'T'HHmmss'Z' format. The date returned is in the UTC zone.

      For example, given an Instant with millis-value of 1416863450581, this method returns "20141124T211050Z"

    • hashCanonicalRequest

      public static String hashCanonicalRequest(String canonicalRequestString)
      Create a hash of the canonical request string

      Step 2 of the AWS Signature version 4 calculation. Refer to https://docs.aws.amazon.com/IAM/latest/UserGuide/create-signed-request.html#create-canonical-request-hash.

    • deriveSigningKey

      public static byte[] deriveSigningKey(AwsCredentialsIdentity credentials, CredentialScope credentialScope)
      Get the signing key based on the given credentials and a credential-scope
    • sign

      public static byte[] sign(String stringData, byte[] key)
      Sign given data using a key.
    • sign

      public static byte[] sign(byte[] data, byte[] key, SigningAlgorithm algorithm)
      Sign given data using a key and a specific algorithm
    • computeSignature

      public static byte[] computeSignature(String stringToSign, byte[] signingKey)
      Compute the signature of a string using a signing key.

      Step 4 of the AWS Signature version 4 calculation. Refer to https://docs.aws.amazon.com/IAM/latest/UserGuide/create-signed-request.html#calculate-signature.

    • addHostHeader

      public static void addHostHeader(SdkHttpRequest.Builder requestBuilder)
      Add the host header based on parameters of a request
    • addDateHeader

      public static void addDateHeader(SdkHttpRequest.Builder requestBuilder, String dateTime)
      Add a date header using a datetime string
    • moveContentLength

      public static long moveContentLength(SdkHttpRequest.Builder request, InputStream payload)
      Move `Content-Length` to `x-amz-decoded-content-length` if not already present. If `Content-Length` is not present, then the payload is read in its entirety to calculate the length.
    • getBinaryRequestPayloadStream

      public static InputStream getBinaryRequestPayloadStream(ContentStreamProvider streamProvider)
    • hash

      public static byte[] hash(InputStream input)
    • hash

      public static byte[] hash(ByteBuffer input)
    • hash

      public static byte[] hash(byte[] data)
    • hash

      public static byte[] hash(String text)
    • getContentHash

      public static String getContentHash(SdkHttpRequest.Builder requestBuilder)