private function getKeyPath(Memento\Key $key = null)
    {
        $pathParts = array();

        // determine group key path
        if (!is_null($this->groupKey)) {
            $keyFileName = base64_encode($this->groupKey->getKey());
            // key filenames should be stored encoded for security
            $keyPartition = abs(crc32($keyFileName)) % Memento\Engine\File::DIR_PARTITION_COUNT;
            $pathParts[] = $keyPartition . DIRECTORY_SEPARATOR . $keyFileName;
        }

        // determine single key path
        if (!is_null($key)) {
            $keyFileName = base64_encode($key->getKey());
            // key filenames should be stored encoded for security
            $keyPartition = abs(crc32($keyFileName)) % Memento\Engine\File::DIR_PARTITION_COUNT;
            $pathParts[] = $keyPartition . DIRECTORY_SEPARATOR . $keyFileName;
        }

        $keyPath = $this->storagePath . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $pathParts);

        if (!is_dir($keyPath)) {
            @mkdir($keyPath, 0777, true);
        }

        return $keyPath;
    }