import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.PBEKeySpec; public class MainClass { public static void main(String[] args) throws Exception { PBEKeySpec keySpec = new PBEKeySpec("charArray".toCharArray()); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); SecretKey key = keyFactory.generateSecret(keySpec); System.out.println(new String(key.getEncoded())); } }