Придумал механизм, все работает как часы, а валидатору опять все не нравится, он ужасен....
package com.javarush.task.task18.task1826;
/*
Шифровка
*/
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
import java.io.*;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
public class Solution {
private final SecretKey key = new SecretKeySpec("ASD12345DSA54321".getBytes(), "AES");
private static StringBuilder sb = new StringBuilder();
private static String line;
public void Cript(String fileName,String fileOutputName) throws NoSuchPaddingException, NoSuchAlgorithmException,
InvalidKeyException, BadPaddingException, IllegalBlockSizeException, IOException {
BufferedReader reader = new BufferedReader(new FileReader(fileName));
while ((line=reader.readLine())!=null){
sb.append(line);
}
reader.close();
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] newCipherText = cipher.doFinal(sb.toString().getBytes());
FileOutputStream flushCriptTEXT = new FileOutputStream(fileOutputName);
flushCriptTEXT.write(newCipherText);
flushCriptTEXT.close();
}
public void deCript(String fileName, String fileOutputName) throws NoSuchPaddingException, NoSuchAlgorithmException,
InvalidKeyException, BadPaddingException, IllegalBlockSizeException, IOException {
FileInputStream fileReaderForDecript = new FileInputStream(fileName);
byte[]bytes=new byte[fileReaderForDecript.available()];
while (fileReaderForDecript.available()>0){
fileReaderForDecript.read(bytes);
}
fileReaderForDecript.close();
Cipher decriptCipher = Cipher.getInstance("AES");
decriptCipher.init(Cipher.DECRYPT_MODE, key);
byte[] decriptText=decriptCipher.doFinal(bytes);
FileOutputStream flushDecriptTEXT = new FileOutputStream(fileOutputName);
flushDecriptTEXT.write(decriptText);
flushDecriptTEXT.close();
}
public static void main(String[] args) throws NoSuchPaddingException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, InvalidKeyException, IOException {
Solution solution = new Solution();
if (args[0].equals("-c")){
solution.Cript(args[1], args[2]);
}if (args[0].equals("-d")){
solution.deCript(args[1], args[2]);
}
}
}