/** Write a password in opaque form to a file for use with the FilePassword * accessor in conjunction with the JaasSecurityDomain * {CLASS}org.jboss.security.plugins.FilePassword:password-file * format of the KeyStorePass attribute. * * @param args */ public static void main(String[] args) throws Exception { if( args.length != 4 ) { System.err.println( "Write a password in opaque form to a file for use with the FilePassword accessor" +"Usage: FilePassword salt count password password-file" +" salt : an 8 char sequence for PBEKeySpec" +" count : iteration count for PBEKeySpec" +" password : the clear text password to write" +" password-file : the path to the file to write the password to" ); } byte[] salt = args[0].substring(0, 8).getBytes(); int count = Integer.parseInt(args[1]); byte[] passwordBytes = args[2].getBytes("UTF-8"); RandomAccessFile passwordFile = new RandomAccessFile(args[3], "rws"); encode(passwordFile, salt, count, passwordBytes); } }
public char[] toCharArray() throws IOException { RandomAccessFile raf = new RandomAccessFile(passwordFile, "rws"); try { char[] password = decode(raf); return password; } catch(Exception e) { Logger log = Logger.getLogger(FilePassword.class); log.error("Failed to decode password file: "+passwordFile, e); throw new IOException(e.getMessage()); } }
/** Write a password in opaque form to a file for use with the FilePassword * accessor in conjunction with the JaasSecurityDomain * {CLASS}org.jboss.security.plugins.FilePassword:password-file * format of the KeyStorePass attribute. * * @param args */ public static void main(String[] args) throws Exception { if( args.length != 4 ) { System.err.println(PicketBoxMessages.MESSAGES.filePasswordUsageMessage()); } byte[] salt = args[0].substring(0, 8).getBytes(); int count = Integer.parseInt(args[1]); byte[] passwordBytes = args[2].getBytes("UTF-8"); RandomAccessFile passwordFile = new RandomAccessFile(args[3], "rws"); encode(passwordFile, salt, count, passwordBytes); } }