public static String getVersion2SignedRequest ( String requestMethod , String protocol , String endpoint , String requestURI , Map < String , String > params , String awsAccessKeyId , String awsSecretKey ) throws SignatureException { if ( ( requestMethod == null ) || ( protocol == null ) || ( endpoint == null ) || ( requestURI == null ) || ( params == null ) || ( awsAccessKeyId == null ) || ( awsSecretKey == null ) ) { throw new IllegalArgumentException ( "Null parameter passed in" ) ; } params . put ( "AWSAccessKeyId" , awsAccessKeyId ) ; params . put ( "SignatureMethod" , HMAC_SHA256_ALGORITHM ) ; params . put ( "SignatureVersion" , "2" ) ; params . put ( "Timestamp" , getTimestamp ( ) ) ; String canonicalQS = getV2CanonicalizedQueryString ( params ) ; String stringToSign = requestMethod + "\n" + endpoint + "\n" + requestURI + "\n" + canonicalQS ; String signature = createSignature ( stringToSign , awsSecretKey , HMAC_SHA256_ALGORITHM ) ; String request = protocol + "://" + endpoint + requestURI + "?" + canonicalQS + "&Signature=" + signature ; return request ; }
This method returns a complete signed request using HmaSHA256 algorithm using the SignatureVersion 2 scheme . Currently this method creates SignatureVersion 2 based signed requests ONLY for the HTTP GET method . It s the callers the responsibility such as Action and such based on the REST API that they are trying to exercise . This method adds SignatureVersion SignatureMethod AWSAccessKeyId Timestamp and Signature parameters to the request .