Generate SHA1 Hash in Java

package nilpointer.net;

import java.math.BigInteger;
import java.security.MessageDigest;

public class Demo {

	public static void main(String[] args) {

		try {
			String password = "123";
			MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
			messageDigest.update(password.getBytes(), 0, password.length());
			BigInteger i = new BigInteger(1, messageDigest.digest());
			String hash = String.format("%1$032x", i);
			System.out.println("SHA1: " + hash);
		} catch (Exception e) {
			System.err.println(e.getMessage());
		}

	}

}
SHA1: 40bd001563085fc35165329ea1ff5c5ecbdbbeef