This is my first try, based on SecureRandom. There is more code, but only main is relevant:
protected static final String ALGORITHM = "AES";
public static void main(String args[]) {
String stringKey = args[1];
byte[] seedArray = stringKey.getBytes();
SecureRandom sRandom = new SecureRandom(seedArray);
byte[] keyArray = new byte[16];
SecretKey sKey = new SecretKeySpec(keyArray, ALGORITHM);
try
{
Encrypter2 encrypter = new Encrypter2(sKey);
FileInputStream efis = new FileInputStream(args[0]);
FileOutputStream efos = new FileOutputStream("Encrypted");
encrypter.encrypt(efis, efos);
FileInputStream dfis = new FileInputStream("Encrypted");
FileOutputStream dfos = new FileOutputStream("Decrypted.txt");
encrypter.decrypt(dfis, dfos);
} catch (FileNotFoundException e1) {
System.out.println("File not found.");
e1.printStackTrace();
} catch (Exception e) {
System.out.println(e);
}
}
Now this will create a unique key for a string input in Java 1.7, but for some reason randomizes in Java 1.6. Is there another method of generating a user-seeded key that is
...dependent on the string the user inputs? Thanks in advance!

New Topic/Question
Reply



MultiQuote



|