Does anyone know how I can include encryption and decryption in my code? I am using FileInput and FileOutput Stream for serialized files. I have an arraylist of students, and I have an arraylist of books. I can save and read them from their individual files. But for security, I want to encrypt and decrypt them. How do I do that?
private static void ReadBook() {
try {
FileInputStream fi = new FileInputStream("bookData.ser");
ObjectInputStream oi = new ObjectInputStream(fi);
bookList = (ArrayList<Book>) oi.readObject();
oi.close();
} catch (Exception e) {
e.printStackTrace();
}
}
protected static void SaveBook(ArrayList<Book> books) {
ArrayList<Book> tempbookList = books;
try {
FileOutputStream fs = new FileOutputStream("bookData.ser");
ObjectOutputStream os = new ObjectOutputStream(fs);
os.reset();
os.writeObject(tempbookList);
os.close();
} catch (Exception e) {
e.printStackTrace();
}
}
private static void ReadStudent() {
try {
FileInputStream fi = new FileInputStream("studentData.ser");
ObjectInputStream oi = new ObjectInputStream(fi);
studentList = (ArrayList<Student>) oi.readObject();
oi.close();
} catch (Exception e) {
e.printStackTrace();
}
}
protected static void SaveStudent(ArrayList<Student> students) {
ArrayList<Student> tempstudentList = students;
try {
FileOutputStream fs = new FileOutputStream("studentData.ser");
ObjectOutputStream os = new ObjectOutputStream(fs);
os.reset();
os.writeObject(tempstudentList);
os.close();
} catch (Exception e) {
e.printStackTrace();
}