/** * Creates an instance of EncryptedRandomAccessBuffer wrapping underlyingBuffer. Keys for key * encryption and MAC generation are derived from the MasterSecret. If this is a new ERAT then * keys are generated and the footer is written to the end of the underlying RAT. Otherwise the * footer is read from the underlying RAT. * @param type The algorithms to be used for the ERAT * @param underlyingBuffer The underlying RAT that will be storing the data. Must be larger than * the footer size specified in type. * @param masterKey The MasterSecret that will be used to derive various keys. * @param newFile If true, treat it as a new file, and writer a header. If false, the ERAT must * already have been initialised. * @throws IOException * @throws GeneralSecurityException */ public EncryptedRandomAccessBuffer(EncryptedRandomAccessBufferType type, LockableRandomAccessBuffer underlying, MasterSecret masterKey, boolean newFile) throws IOException, GeneralSecurityException{ this.type = type; this.underlyingBuffer = underlying; setup(masterKey, newFile); }
@Override public void onResume(ClientContext context) throws ResumeFailedException { underlyingBuffer.onResume(context); try { setup(context.getPersistentMasterSecret(), false); } catch (IOException e) { Logger.error(this, "Disk I/O error resuming: "+e, e); throw new ResumeFailedException(e); } catch (GeneralSecurityException e) { Logger.error(this, "Impossible security error resuming - maybe we lost a codec?: "+e, e); throw new ResumeFailedException(e); } }