MySQLの次の関数
MD5( 'secret' )
5ebe2294ecd0e0f08eab7690d2a6ee69を生成します
同じ出力を生成するJava関数が欲しいのですが。だが
public static String md5( String source ) {
try {
MessageDigest md = MessageDigest.getInstance( "MD5" );
byte[] bytes = md.digest( source.getBytes("UTF-8") );
return getString( bytes );
} catch( Exception e ) {
e.printStackTrace();
return null;
}
}
private static String getString( byte[] bytes ) {
StringBuffer sb = new StringBuffer();
for( int i=0; i<bytes.length; i++ ) {
byte b = bytes[ i ];
sb.append( ( int )( 0x00FF & b ) );
if( i+1 <bytes.length ) {
sb.append( "-" );
}
}
return sb.toString();
}
生成します
94-190-34-148-236-208-224-240-142-171-118-144-210-166-238-105