Thursday, April 25, 2013

MD5 encrypte password java service

MD5 encrypte password java service

// pipeline
IDataCursor pipelineCursor = pipeline.getCursor();
    String    password = IDataUtil.getString( pipelineCursor, "password" );
        String encodedPasswrd = null ;
try{
MessageDigest md = MessageDigest.getInstance("MD5");
      md.update(password.getBytes());
              byte byteData[] = md.digest();
              //convert the byte to hex format method
              StringBuffer sb = new StringBuffer();
              for (int i = 0; i < byteData.length; i++) {
                      sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
              }
        encodedPasswrd = sb.toString();
}
catch(NoSuchAlgorithmException e){
e.printStackTrace();
}
pipelineCursor.destroy();
// pipeline
IDataCursor pipelineCursor_1 = pipeline.getCursor();
IDataUtil.put( pipelineCursor_1, "encodedPassword", encodedPasswrd );
pipelineCursor_1.destroy();


No comments:

Post a Comment