public static String digestString(String pass,String algorithm) throws NoSuchAlgorithmException {
  MessageDigest md;
  ByteArrayOutputStream bos;
  try {
    md=MessageDigest.getInstance(algorithm);
    byte[] digest=md.digest(pass.getBytes("iso-8859-1"));
    bos=new ByteArrayOutputStream();
    OutputStream encodedStream=MimeUtility.encode(bos,"base64");
    encodedStream.write(digest);
    return bos.toString("iso-8859-1");
  }
 catch (  IOException ioe) {
    throw new RuntimeException("Fatal error: " + ioe);
  }
catch (  MessagingException me) {
    throw new RuntimeException("Fatal error: " + me);
  }
}

public static String digestString ( String pass , String algorithm ) throws NoSuchAlgorithmException { MessageDigest md ; ByteArrayOutputStream bos ; try { md = MessageDigest . getInstance ( algorithm ) ; byte [ ] digest = md . digest ( pass . getBytes ( "iso-8859-1" ) ) ; bos = new ByteArrayOutputStream ( ) ; OutputStream encodedStream = MimeUtility . encode ( bos , "base64" ) ; encodedStream . write ( digest ) ; return bos . toString ( "iso-8859-1" ) ; } catch ( IOException ioe ) { throw new RuntimeException ( "Fatal error: " + ioe ) ; } catch ( MessagingException me ) { throw new RuntimeException ( "Fatal error: " + me ) ; } }
calculate digest of given string using given algorithm . encode digest in mime - like base64 .
