/*
  * Encrypts model class and saves to file
  *
  * @throws IOException File not writable. Most likely encrypted container file is in use by other process
  * @throws CEEncryptionErrorException Error while encrypting. This should not happen unless data corruption while program runs
  */
 protected static final synchronized void seal(Model modelIn, File file, SealObject sealerIn)
     throws IOException, CEEncryptionErrorException {
   try (ObjectOutputStream output =
       new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)))) {
     output.writeObject(sealerIn.encrypt(modelIn));
   } catch (IllegalBlockSizeException ex) {
     Logger.getLogger(ViewerController.class.getName()).log(Level.SEVERE, null, ex);
     throw new CEEncryptionErrorException(
         "Seal method of sealer threw IllegalBlockSize. Encryption error");
   }
 }
 /*
  * Decrypts model class and restores
  *
  * @throws FileNotFoundException - File not found or not readable
  * @throws CEEncryptionErrorException - Errors while attempting to decrypt file. Usually bad password
  */
 protected static final synchronized Model unseal(File file, SealObject sealerIn)
     throws FileNotFoundException, CEEncryptionErrorException {
   try (ObjectInputStream input =
       new ObjectInputStream(new BufferedInputStream(new FileInputStream(file)))) {
     return (Model) sealerIn.decrypt((SealedObject) input.readObject());
   } catch (ClassNotFoundException | IOException ex) {
     JOptionPane.showMessageDialog(
         null,
         "ERROR: Unable to read previous data. Assuming first time run. All data has been lost. \nPlease create a new admin on the next screen",
         "Decryption Failure",
         JOptionPane.ERROR_MESSAGE);
     throw new FileNotFoundException("Previous data unreadable. Attempting to create new file");
   } catch (IllegalBlockSizeException | BadPaddingException ex) {
     Logger.getLogger(ViewerController.class.getName()).log(Level.SEVERE, null, ex);
     throw new CEEncryptionErrorException(
         "IllegalBlockSize or BadPadding thrown by decrypt method of sealer class");
   }
 }