convert password encryption from java to php

Posted by Obay on Stack Overflow See other posts from Stack Overflow or by Obay
Published on 2010-06-02T11:00:58Z Indexed on 2010/06/02 11:03 UTC
Read the original article Hit count: 379

Filed under:
|
|
|
|

I'm trying to create a PHP version of an existing JSP program, however I'm stuck at the password encryption part.

Could you please tell me how to convert this one? I know it tries to get the md5() but after that, I don't get it. I get lost in the Stringbuffer and for() parts.

Can you help me out?

 public static String encryptPassword( String password ) 
 {
     String encrypted = "";
     try
     {
   MessageDigest digest = MessageDigest.getInstance( "MD5" ); 
   byte[] passwordBytes = password.getBytes( ); 

   digest.reset( );
   digest.update( passwordBytes );
   byte[] message = digest.digest( );

   StringBuffer hexString = new StringBuffer();
       for ( int i=0; i < message.length; i++) 
       {
            hexString.append( Integer.toHexString(
                0xFF & message[ i ] ) );
       }
       encrypted = hexString.toString();
  }
  catch( Exception e ) { }
  return encrypted; 
 }

© Stack Overflow or respective owner

Related posts about java

Related posts about php