Package org.eclipse.jgit.transport
Class AwsRequestSignerV4
- java.lang.Object
-
- org.eclipse.jgit.transport.AwsRequestSignerV4
-
public final class AwsRequestSignerV4 extends Object
Utility class for signing requests to AWS service endpoints using the V4 signing protocol. Reference implementation: AWSS3SigV4JavaSamples.zip- Since:
- 5.13
- See Also:
- AWS Signature Version 4
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
calculateBodyHash(byte[] data)
Calculates the hex-encoded SHA-256 hash of the provided byte array.static String
getCanonicalizedQueryString(Map<String,String> queryParameters)
Constructs the canonicalized query string for a request.static byte[]
hash(byte[] data)
Hashes the provided byte array using the SHA-256 algorithm.static void
sign(HttpURLConnection httpURLConnection, Map<String,String> queryParameters, long contentLength, String bodyHash, String serviceName, String regionName, String awsAccessKey, char[] awsSecretKey)
Sign the provided request with an AWS4 signature as the 'Authorization' header.
-
-
-
Method Detail
-
sign
public static void sign(HttpURLConnection httpURLConnection, Map<String,String> queryParameters, long contentLength, String bodyHash, String serviceName, String regionName, String awsAccessKey, char[] awsSecretKey)
Sign the provided request with an AWS4 signature as the 'Authorization' header.- Parameters:
httpURLConnection
- The request to sign.queryParameters
- The query parameters being sent in the request.contentLength
- The content length of the data being sent in the requestbodyHash
- Hex-encoded SHA-256 hash of the data being sent in the requestserviceName
- The signing name of the AWS service (e.g. "s3").regionName
- The name of the AWS region that will handle the request (e.g. "us-east-1").awsAccessKey
- The user's AWS Access Key.awsSecretKey
- The user's AWS Secret Key.
-
calculateBodyHash
public static String calculateBodyHash(byte[] data)
Calculates the hex-encoded SHA-256 hash of the provided byte array.- Parameters:
data
- Byte array to hash- Returns:
- Hex-encoded SHA-256 hash of the provided byte array.
-
getCanonicalizedQueryString
public static String getCanonicalizedQueryString(Map<String,String> queryParameters)
Constructs the canonicalized query string for a request.- Parameters:
queryParameters
- The query parameters in the request.- Returns:
- The canonicalized query string for the request.
-
hash
public static byte[] hash(byte[] data)
Hashes the provided byte array using the SHA-256 algorithm.- Parameters:
data
- The byte array to hash.- Returns:
- Hashed string contents of the provided byte array.
-
-