public static String calculateResponse ( String algorithm , String username_value , String realm_value , String passwd , String nonce_value , String nc_value , String cnonce_value , String Method , String digest_uri_value , String entity_body , String qop_value ) { if ( username_value == null || realm_value == null || passwd == null || Method == null || digest_uri_value == null || nonce_value == null ) throw new NullPointerException ( "Null parameter to MessageDigestAlgorithm.calculateResponse()" ) ; // The following follows closely the algorithm for generating a response // digest as specified by rfc2617 String A1 = null ; if ( algorithm == null || algorithm . trim ( ) . length ( ) == 0 || algorithm . trim ( ) . equalsIgnoreCase ( "MD5" ) ) { A1 = username_value + ":" + realm_value + ":" + passwd ; } else { if ( cnonce_value == null || cnonce_value . length ( ) == 0 ) throw new NullPointerException ( "cnonce_value may not be absent for MD5-Sess algorithm." ) ; A1 = H ( username_value + ":" + realm_value + ":" + passwd ) + ":" + nonce_value + ":" + cnonce_value ; } String A2 = null ; if ( qop_value == null || qop_value . trim ( ) . length ( ) == 0 || qop_value . trim ( ) . equalsIgnoreCase ( "auth" ) ) { A2 = Method + ":" + digest_uri_value ; } else { if ( entity_body == null ) entity_body = "" ; A2 = Method + ":" + digest_uri_value + ":" + H ( entity_body ) ; } String request_digest = null ; if ( cnonce_value != null && qop_value != null && ( qop_value . equals ( "auth" ) || ( qop_value . equals ( "auth-int" ) ) ) ) { request_digest = KD ( H ( A1 ) , nonce_value + ":" + nc_value + ":" + cnonce_value + ":" + qop_value + ":" + H ( A2 ) ) ; } else { request_digest = KD ( H ( A1 ) , nonce_value + ":" + H ( A2 ) ) ; } return request_digest ; }
Calculates a response an http authentication response in accordance with rfc2617 .