protected static void constructSignatureForRequestParameters(
            List<NameValuePair> params, String secretKey, long currentTimeSeconds) {
        // First, inject a 'timestamp=' parameter containing the current time in seconds since Jan 1st 1970
        params.add(new BasicNameValuePair(PARAM_TIMESTAMP, Long.toString(currentTimeSeconds)));

        Map<String, String> sortedParams = new TreeMap<>();
        for (NameValuePair param: params) {
            String name = param.getName();
            String value = param.getValue();
            if (name.equals(PARAM_SIGNATURE))
                continue;
            if (value == null)
                value = "";
            if (!value.trim().equals(""))
                sortedParams.put(name, value);
        }

        // Now, walk through the sorted list of parameters and construct a string
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, String> param: sortedParams.entrySet()) {
            String name = param.getKey();
            String value = param.getValue();
            sb.append("&").append(clean(name)).append("=").append(clean(value));
        }

        // Now, append the secret key, and calculate an MD5 signature of the resultant string
        sb.append(secretKey);

        String str = sb.toString();

        String md5 = "no signature";
        try {
            md5 = MD5Util.calculateMd5(str);
        } catch (Exception e) {
            log.error("error...", e);
        }

        log.debug("SECURITY-KEY-GENERATION -- String [ " + str + " ] Signature [ " + md5 + " ] ");

        params.add(new BasicNameValuePair(PARAM_SIGNATURE, md5));
    }
protected static void constructSignatureForRequestParameters ( List < NameValuePair > params , String secretKey , long currentTimeSeconds ) { params . add ( new BasicNameValuePair ( PARAM_TIMESTAMP , Long . toString ( currentTimeSeconds ) ) ) ; Map < String , String > sortedParams = new TreeMap < > ( ) ; for ( NameValuePair param : params ) { String name = param . getName ( ) ; String value = param . getValue ( ) ; if ( name . equals ( PARAM_SIGNATURE ) ) continue ; if ( value == null ) value = "" ; if ( ! value . trim ( ) . equals ( "" ) ) sortedParams . put ( name , value ) ; } StringBuilder sb = new StringBuilder ( ) ; for ( Map . Entry < String , String > param : sortedParams . entrySet ( ) ) { String name = param . getKey ( ) ; String value = param . getValue ( ) ; sb . append ( "&" ) . append ( clean ( name ) ) . append ( "=" ) . append ( clean ( value ) ) ; } sb . append ( secretKey ) ; String str = sb . toString ( ) ; String md5 = "no signature" ; try { md5 = MD5Util . calculateMd5 ( str ) ; } catch ( Exception e ) { log . error ( "error..." , e ) ; } log . debug ( "SECURITY-KEY-GENERATION -- String [ " + str + " ] Signature [ " + md5 + " ] " ) ; params . add ( new BasicNameValuePair ( PARAM_SIGNATURE , md5 ) ) ; }
Signs a set of request parameters.
<p>
Generates additional parameters to represent the timestamp and generated signature.
Uses the supplied pre-shared secret key to generate the signature.

@param params List of NameValuePair instances containing the query parameters for the request that is to be signed
@param secretKey the pre-shared secret key held by the client
@param currentTimeSeconds the current time in seconds since 1970-01-01