Index: source/org/jivesoftware/smack/sasl/SASLDigestMD5Mechanism.java
===================================================================
--- source/org/jivesoftware/smack/sasl/SASLDigestMD5Mechanism.java	(revision 11361)
+++ source/org/jivesoftware/smack/sasl/SASLDigestMD5Mechanism.java	(working copy)
@@ -20,7 +20,9 @@
 package org.jivesoftware.smack.sasl;
 
 import org.jivesoftware.smack.SASLAuthentication;
+import org.jivesoftware.smack.util.Base64;
 
+import java.io.IOException;
 /**
  * Implementation of the SASL DIGEST-MD5 mechanism
  *
@@ -35,4 +37,43 @@
     protected String getName() {
         return "DIGEST-MD5";
     }
-}
+
+
+    /**
+     * The server is challenging the SASL mechanism for the stanza he just sent. Send a
+     * response to the server's challenge.
+     *
+     * @param challenge a base64 encoded string representing the challenge.
+     * @throws IOException if an exception sending the response occurs.
+     */
+    public void challengeReceived(String challenge) throws IOException {
+        // Build the challenge response stanza encoding the response text
+        StringBuilder stanza = new StringBuilder();
+
+        byte response[];
+        if(challenge != null) {
+            response = sc.evaluateChallenge(Base64.decode(challenge));
+        } else {
+            response = sc.evaluateChallenge(null);
+        }
+
+       String authenticationText = null;
+       if (response != null) {
+            authenticationText = Base64.encodeBytes(response,Base64.DONT_BREAK_LINES);
+            if(authenticationText.equals("")) {
+                authenticationText = "=";
+            }
+       }
+
+       if (authenticationText != null) {
+            stanza.append("<response xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">");
+            stanza.append(authenticationText);
+            stanza.append("</response>");
+       } else {
+            stanza.append("<response xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\" />");
+       }
+
+        // Send the authentication to the server
+        getSASLAuthentication().send(stanza.toString());
+    }
+ }
