---
name: "zip_fopen_index_encrypted"
section: "3"
platform: "linux"
package: "libzip"
version: "1.11.4-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/zip_fopen_index_encrypted"
---

# zip\_fopen\_index\_encrypted(3)

open encrypted file in zip archive for reading

## NAME

**zip\_fopen\_encrypted**, **zip\_fopen\_index\_encrypted** – open encrypted file in zip archive for reading

## LIBRARY

libzip (-lzip)

## SYNOPSIS

**#include \<zip.h\>**

*zip\_file\_t* *\**\

**zip\_fopen\_encrypted**(*zip\_t \*archive*, *const char \*fname*, *zip\_flags\_t flags*, *const char \*password*);

*zip\_file\_t* *\**\

**zip\_fopen\_index\_encrypted**(*zip\_t \*archive*, *zip\_uint64\_t index*, *zip\_flags\_t flags*, *const char \*password*);

## DESCRIPTION

The **zip\_fopen\_encrypted**() function opens the encrypted file name *fname* in *archive* using the password given in the *password* argument. If *password* is NULL or the empty string, the default password is used (see [zip\_set\_default\_password(3)](/zip_set_default_password/3.md)). The *flags* argument are the same as for [zip\_fopen(3)](/zip_fopen/3.md).

The **zip\_fopen\_index\_encrypted**() function opens the file at position *index*, see [zip\_fopen\_index(3)](/zip_fopen_index/3.md). These functions are called automatically by [zip\_fopen(3)](/zip_fopen/3.md); you only need to call them if you want to specify a non-default password (see [zip\_set\_default\_password(3)](/zip_set_default_password/3.md)).

## RETURN VALUES

Upon successful completion, a *struct* *zip\_file* pointer is returned. Otherwise, NULL is returned and the error code in *archive* is set to indicate the error.

## ERRORS

- \[ZIP\_ER\_NOPASSWD\]

  No password was provided.

The function **zip\_fopen\_encrypted**() may also fail and set *zip\_err* for any of the errors specified for the routine [zip\_fopen(3)](/zip_fopen/3.md).

The function **zip\_fopen\_index\_encrypted**() may also fail and set *zip\_err* for any of the errors specified for the routine [zip\_fopen\_index(3)](/zip_fopen_index/3.md).

## SEE ALSO

[libzip(3)](/libzip/3.md), [zip\_fclose(3)](/zip_fclose/3.md), [zip\_fopen(3)](/zip_fopen/3.md), [zip\_fread(3)](/zip_fread/3.md), [zip\_get\_num\_entries(3)](/zip_get_num_entries/3.md), [zip\_name\_locate(3)](/zip_name_locate/3.md)

## HISTORY

**zip\_fopen\_encrypted**() and **zip\_fopen\_index\_encrypted**() were added in libzip 1.0.

## AUTHORS

Dieter Baron ⟨*dillo@nih.at*⟩ and Thomas Klausner ⟨*wiz@gatalith.at*⟩

## CAVEATS

The zip file format provides very limited possibility for password verification (a short hash of is compared against one byte in the zip archive). For this reason, reading a file while using an incorrect password may immediately fail with ZIP\_ER\_WRONGPASSWD, but if the mismatch is not detected, a zlib error may be returned later instead. Since zlib errors can also be caused by broken compressed data, there is no way to make sure if the password was incorrect or if it was correct, but the compressed data was invalid.
