title: Equivalent of PHP's crypt function in Java
body: <p>I am migrating my PHP code to Google App Engine - Java.<br>
  So I need an equivalent of PHP's crypt function in Java,<br>
  since I have stored all the passwords of registered users<br>
  using crypt in my DB.    </p>
  
  <p><strong>Edit 1</strong>: 
  Here is my php code for encrypting passwords :   </p>
  
  <p>$password = "test123";<br>
  $pwd = crypt($password,$password);<br>
  echo $pwd;  </p>
  
  <p>Output is (On <strong>Windows</strong> as well as a linux based server on <strong>HostMonser</strong>):<br>
  <strong>temjCCsjBECmU</strong>  </p>
  
  <p>Can someone give me equivalted java code?<br>
  I have tried various permutations &amp; combinations with<br>
  MessageDigest class, but can't get it right..  </p>
  
  <p><strong>Edit 2</strong>:<br>
  Here is sample code which I thought would work but did not:  </p>
  
  <pre><code>try {
                  {
                      String password = "test123";
                      MessageDigest digest = MessageDigest.getInstance( "MD5" ); 
                      byte[] passwordBytes = password.getBytes( ); 
  
                      digest.reset( );
                      digest.update( passwordBytes );
                      digest.update( passwordBytes );
                      byte[] message = digest.digest( );
  
                      StringBuffer hexString = new StringBuffer();
                      for ( int i=0; i &lt; message.length; i++) 
                      {
                          hexString.append( Integer.toHexString(
                              0xFF &amp; message[ i ] ) );
                      }
                      String encrypted = hexString.toString();
                      System.out.println(encrypted);
                    } } catch (NoSuchAlgorithmException e1) {
                  // TODO Auto-generated catch block
                  e1.printStackTrace();
              }
  </code></pre>