keepassphp/lib/kdbxfile.php
public function prepareEncrypting(&$error)
	{
		$header = $this->getHeader();
		$header->masterSeed = random_bytes(self::SEED_LEN);
		$header->transformSeed = random_bytes(self::SEED_LEN);
		$header->encryptionIV = random_bytes(16);
		$header->randomStreamKey = random_bytes(self::SEED_LEN);
		$header->startBytes = random_bytes(self::STARTBYTES_LEN);

		if($header->randomStream == KdbxHeader::RANDOMSTREAM_SALSA20)
		{
			$this->_randomStream = Salsa20Stream::create(
				hash(self::HASH, $header->randomStreamKey, true),
				self::SALSA20_IV);
			if($this->_randomStream == null)
			{
				$error = "Kdbx file encrypt: random stream parameters error.";
				return false;
			}
		}

		$result = $header->toBinary(self::HASH);

		if(!self::headerCheck($header))
		{
			$error = "Kdbx file encrypt: header check failed.";
			return false;
		}

		$this->_headerBinary = $result;
		return true;
	}
public function prepareEncrypting(&$error)
	{
		$header = $this->getHeader();
		$header->masterSeed = random_bytes(self::SEED_LEN);
		$header->transformSeed = random_bytes(self::SEED_LEN);
		$header->encryptionIV = random_bytes(16);
		$header->randomStreamKey = random_bytes(self::SEED_LEN);
		$header->startBytes = random_bytes(self::STARTBYTES_LEN);

		if($header->randomStream == KdbxHeader::RANDOMSTREAM_SALSA20)
		{
			$this->_randomStream = Salsa20Stream::create(
				hash(self::HASH, $header->randomStreamKey, true),
				self::SALSA20_IV);
			if($this->_randomStream == null)
			{
				$error = "Kdbx file encrypt: random stream parameters error.";
				return false;
			}
		}

		$result = $header->toBinary(self::HASH);

		if(!self::headerCheck($header))
		{
			$error = "Kdbx file encrypt: header check failed.";
			return false;
		}

		$this->_headerBinary = $result;
		return true;
	}
public function prepareEncrypting ( & $ error ) { $ header = $ this -> getHeader ( ) ; $ header -> masterSeed = random_bytes ( self :: SEED_LEN ) ; $ header -> transformSeed = random_bytes ( self :: SEED_LEN ) ; $ header -> encryptionIV = random_bytes ( 16 ) ; $ header -> randomStreamKey = random_bytes ( self :: SEED_LEN ) ; $ header -> startBytes = random_bytes ( self :: STARTBYTES_LEN ) ; if ( $ header -> randomStream == KdbxHeader :: RANDOMSTREAM_SALSA20 ) { $ this -> _randomStream = Salsa20Stream :: create ( hash ( self :: HASH , $ header -> randomStreamKey , true ) , self :: SALSA20_IV ) ; if ( $ this -> _randomStream == null ) { $ error = "Kdbx file encrypt: random stream parameters error." ; return false ; } } $ result = $ header -> toBinary ( self :: HASH ) ; if ( ! self :: headerCheck ( $ header ) ) { $ error = "Kdbx file encrypt: header check failed." ; return false ; } $ this -> _headerBinary = $ result ; return true ; }
Prepares the encryption of this instance by generating new random
strings for the header, serializing the header and computing its hash.
Non-random header fields must be set before calling this method.
@param &$error A string that will receive a message in case of error.
@return true if everything went well and the encrypt method can be
called, false otherwise.
Prepares the encryption of this instance by generating new random strings for the header serializing the header and computing its hash . Non - random header fields must be set before calling this method .