JSP SHA1 encrypt

<%@page import="java.security.*" %>
public static String encrypt(String plainText) throws Exception {
 MessageDigest mdAlgorithm = MessageDigest.getInstance("SHA-1");
 mdAlgorithm.update(plainText.getBytes());
 byte[] digest = mdAlgorithm.digest();
 StringBuffer hexString = new StringBuffer();
 for (int i = 0; i < digest.length; i++) {
 plainText = Integer.toHexString(0xFF & digest[i]);

if (plainText.length() < 2) {
 plainText = "0" + plainText;
 }
 hexString.append(plainText);
 }
 return hexString.toString();
 }

因為最近在忙jsp所以寫了個函式