import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import sun.misc.BASE64Encoder; public class enc{ public static void main(String[] args){ String plaintext = "password"; MessageDigest md = null; try { md = MessageDigest.getInstance("SHA"); } catch(NoSuchAlgorithmException e) { System.exit(1); } try { //Encoding into UTF-8 System.out.print("UTF-8 : "); for(byte b : plaintext.getBytes("UTF-8")){ System.out.print(b); } System.out.println(); md.update(plaintext.getBytes("UTF-8")); } catch(UnsupportedEncodingException e) { System.exit(1); } byte raw[] = md.digest(); System.out.print("Encrypted Bytes : "); for(byte b : raw){ System.out.print(b); } System.out.println(); String hash = (new BASE64Encoder()).encode(raw); System.out.println("Encoded: " + hash); }}