public static function load(Reader $reader, $hashAlgo, &$error)
	{
		$dreader = new DigestReader($reader, $hashAlgo);
		
		$sig1 = $dreader->read(4);
		$sig2 = $dreader->read(4);
		if($sig1 != self::SIGNATURE1 || $sig2 != self::SIGNATURE2)
		{
			$error = "Kdbx header: signature not correct.";
			return null;
		}

		$lowerversion = $dreader->readNumber(2);
		$upperversion = $dreader->readNumber(2);
		if($upperversion > self::MAXIMAL_VERSION)
		{
			$error = "Kdbx header: version not supported.";
			return null;
		}

		$header = new KdbxHeader();
		$ended = false;
		while(!$ended)
		{
			$fieldId = $dreader->readByte();
			$fieldLen = $dreader->readNumber(2);
			$field = null;
			if($fieldLen > 0)
			{
				$field = $dreader->read($fieldLen);
				if($field == null || strlen($field) != $fieldLen)
				{
					$error = "Kdbx header: uncomplete header field.";
					return null;
				}
			}
			
			/*
			 * end of header
			 */
			if($fieldId == 0)
				$ended = true;

			/*
			 * comment (let's ignore)
			 */
			//elseif($fieldId == 1)
			//	;

			/*
			 * Cipher type
			 */
			elseif($fieldId == 2)
				$header->cipher = $field;

			/*
			 * Compression method
			 */
			elseif($fieldId == 3)
			{
				if($field == self::INT_0)
					$header->compression = self::COMPRESSION_NONE;
				elseif($field == self::INT_1)
					$header->compression = self::COMPRESSION_GZIP;
			}

			/*
			 *  MasterSeed
			 */
			elseif($fieldId == 4)
				$header->masterSeed = $field;

			 /*
			  * TransformSeed
			  */
			elseif($fieldId == 5)
				$header->transformSeed = $field;

			/*
			 * Number of rounds
			 */
			elseif($fieldId == 6)
				$header->rounds = $field;

			/*
			 * EncryptionIV
			 */
			elseif($fieldId == 7)
				$header->encryptionIV = $field;

			/*
			 * Random stream key
			 */
			elseif($fieldId == 8)
				$header->randomStreamKey = $field;

			/*
			 * First bytes of result
			 */
			elseif($fieldId == 9)
				$header->startBytes = $field;

			/*
			 * Random stream type
			 */
			elseif($fieldId == 10)
			{
				if($field == self::INT_0)
					$header->randomStream = self::RANDOMSTREAM_NONE;
				elseif($field == self::INT_2)
					$header->randomStream = self::RANDOMSTREAM_SALSA20;
				/*elseif($field == self::INT_1) // unsuported
					$header->randomStream= self::RANDOMSTREAM_ARC4;*/
			}
		}
		$header->headerHash = $dreader->GetDigest();
		$error = null;
		return $header;
	}