public synchronized byte[] generateLogEntryMAC(String LogEntry) throws Exception {
  byte[] key=null;
  lastMac=currentMAC;
  key=readFromSecretStore(logFileName,currentKey,loggerPass);
  if ((currentLoggerKey != null) && (equalByteArrays(currentLoggerKey,key) == false)) {
    throw new Exception("Possible Intrusion or " + " Misconfiguration");
  }
  currentLoggerKey=key;
  currentMAC=getDigest(LogEntry,currentLoggerKey);
  MessageDigest md=MessageDigest.getInstance("SHA");
  md.update(currentLoggerKey);
  currentLoggerKey=md.digest();
  writeToSecretStore(currentLoggerKey,logFileName,loggerPass,currentKey);
  return currentMAC;
}

public synchronized byte [ ] generateLogEntryMAC ( String LogEntry ) throws Exception { byte [ ] key = null ; lastMac = currentMAC ; key = readFromSecretStore ( logFileName , currentKey , loggerPass ) ; if ( ( currentLoggerKey != null ) && ( equalByteArrays ( currentLoggerKey , key ) == false ) ) { throw new Exception ( "Possible Intrusion or " + " Misconfiguration" ) ; } currentLoggerKey = key ; currentMAC = getDigest ( LogEntry , currentLoggerKey ) ; MessageDigest md = MessageDigest . getInstance ( "SHA" ) ; md . update ( currentLoggerKey ) ; currentLoggerKey = md . digest ( ) ; writeToSecretStore ( currentLoggerKey , logFileName , loggerPass , currentKey ) ; return currentMAC ; }
returns the current key from secure storage , generates the mac and also generates a new key and stores it back in the secure storage . does not store the initialkey into the log file but replaces it with the currentkey
