· 7 years ago · Jan 13, 2019, 02:58 AM
1User-input seed for AES encryption in Java
2protected static final String ALGORITHM = "AES";
3
4public static void main(String args[]) {
5
6 String stringKey = args[1];
7 byte[] seedArray = stringKey.getBytes();
8 SecureRandom sRandom = new SecureRandom(seedArray);
9 byte[] keyArray = new byte[16];
10 SecretKey sKey = new SecretKeySpec(keyArray, ALGORITHM);
11
12 try
13 {
14
15 Encrypter2 encrypter = new Encrypter2(sKey);
16
17 FileInputStream efis = new FileInputStream(args[0]);
18 FileOutputStream efos = new FileOutputStream("Encrypted");
19 encrypter.encrypt(efis, efos);
20
21 FileInputStream dfis = new FileInputStream("Encrypted");
22 FileOutputStream dfos = new FileOutputStream("Decrypted.txt");
23 encrypter.decrypt(dfis, dfos);
24
25 } catch (FileNotFoundException e1) {
26 System.out.println("File not found.");
27 e1.printStackTrace();
28 } catch (Exception e) {
29 System.out.println(e);
30 }
31}