public static KdbxHeader readKdbxHeader(KdbxHeader kdbxHeader,InputStream inputStream) throws IOException {
  MessageDigest digest=Encryption.getMessageDigestInstance();
  DigestInputStream digestInputStream=new DigestInputStream(inputStream,digest);
  LittleEndianDataInputStream ledis=new LittleEndianDataInputStream(digestInputStream);
  if (!verifyMagicNumber(ledis)) {
    throw new IllegalStateException("Magic number did not match");
  }
  if (!verifyFileVersion(ledis)) {
    throw new IllegalStateException("File version did not match");
  }
  byte headerType;
  while ((headerType=ledis.readByte()) != HeaderType.END) {
switch (headerType) {
case HeaderType.COMMENT:
      getByteArray(ledis);
    break;
case HeaderType.CIPHER_ID:
  kdbxHeader.setCipherUuid(getByteArray(ledis));
break;
case HeaderType.COMPRESSION_FLAGS:
kdbxHeader.setCompressionFlags(getInt(ledis));
break;
case HeaderType.MASTER_SEED:
kdbxHeader.setMasterSeed(getByteArray(ledis));
break;
case HeaderType.TRANSFORM_SEED:
kdbxHeader.setTransformSeed(getByteArray(ledis));
break;
case HeaderType.TRANSFORM_ROUNDS:
kdbxHeader.setTransformRounds(getLong(ledis));
break;
case HeaderType.ENCRYPTION_IV:
kdbxHeader.setEncryptionIv(getByteArray(ledis));
break;
case HeaderType.PROTECTED_STREAM_KEY:
kdbxHeader.setProtectedStreamKey(getByteArray(ledis));
break;
case HeaderType.STREAM_START_BYTES:
kdbxHeader.setStreamStartBytes(getByteArray(ledis));
break;
case HeaderType.INNER_RANDOM_STREAM_ID:
kdbxHeader.setInnerRandomStreamId(getInt(ledis));
break;
default :
throw new IllegalStateException("Unknown File Header");
}
}
getByteArray(ledis);
kdbxHeader.setHeaderHash(digest.digest());
return kdbxHeader;
}

public static KdbxHeader readKdbxHeader ( KdbxHeader kdbxHeader , InputStream inputStream ) throws IOException { MessageDigest digest = Encryption . getMessageDigestInstance ( ) ; DigestInputStream digestInputStream = new DigestInputStream ( inputStream , digest ) ; LittleEndianDataInputStream ledis = new LittleEndianDataInputStream ( digestInputStream ) ; if ( ! verifyMagicNumber ( ledis ) ) { throw new IllegalStateException ( "Magic number did not match" ) ; } if ( ! verifyFileVersion ( ledis ) ) { throw new IllegalStateException ( "File version did not match" ) ; } byte headerType ; while ( ( headerType = ledis . readByte ( ) ) != HeaderType . END ) { switch ( headerType ) { case HeaderType . COMMENT : getByteArray ( ledis ) ; break ; case HeaderType . CIPHER_ID : kdbxHeader . setCipherUuid ( getByteArray ( ledis ) ) ; break ; case HeaderType . COMPRESSION_FLAGS : kdbxHeader . setCompressionFlags ( getInt ( ledis ) ) ; break ; case HeaderType . MASTER_SEED : kdbxHeader . setMasterSeed ( getByteArray ( ledis ) ) ; break ; case HeaderType . TRANSFORM_SEED : kdbxHeader . setTransformSeed ( getByteArray ( ledis ) ) ; break ; case HeaderType . TRANSFORM_ROUNDS : kdbxHeader . setTransformRounds ( getLong ( ledis ) ) ; break ; case HeaderType . ENCRYPTION_IV : kdbxHeader . setEncryptionIv ( getByteArray ( ledis ) ) ; break ; case HeaderType . PROTECTED_STREAM_KEY : kdbxHeader . setProtectedStreamKey ( getByteArray ( ledis ) ) ; break ; case HeaderType . STREAM_START_BYTES : kdbxHeader . setStreamStartBytes ( getByteArray ( ledis ) ) ; break ; case HeaderType . INNER_RANDOM_STREAM_ID : kdbxHeader . setInnerRandomStreamId ( getInt ( ledis ) ) ; break ; default : throw new IllegalStateException ( "Unknown File Header" ) ; } } getByteArray ( ledis ) ; kdbxHeader . setHeaderHash ( digest . digest ( ) ) ; return kdbxHeader ; }
populate a kdbxheader from the input stream supplied
