import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import sun.misc.BASE64Encoder; public class x{ public static String encrypt(String plaintext){ MessageDigest md = null; try{ //Set encryption type, and set text to encrypt md = MessageDigest.getInstance("SHA"); md.update(plaintext.getBytes("UTF-8")); } catch(Exception e) { return ""; } //Encrypt bytes and return value byte raw[] = md.digest(); return (new BASE64Encoder()).encode(raw); }