/* * 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"); } }