---
name: "zip_file_set_encryption"
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_file_set_encryption"
---

# zip\_file\_set\_encryption(3)

set encryption method for file in zip

## NAME

**zip\_file\_set\_encryption** – set encryption method for file in zip

## LIBRARY

libzip (-lzip)

## SYNOPSIS

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

*int*\

**zip\_file\_set\_encryption**(*zip\_t \*archive*, *zip\_uint64\_t index*, *zip\_uint16\_t method*, *const char \*password*);

## DESCRIPTION

The **zip\_file\_set\_encryption**() function sets the encryption method for the file at position *index* in the zip archive to *method* using the password *password*. The *method* is the same as returned by [zip\_stat(3)](/zip_stat/3.md). For the *method* argument, currently only the following values are supported:

- ZIP\_EM\_NONE

  No encryption.

- ZIP\_EM\_AES\_128

  Winzip AES-128 encryption.

- ZIP\_EM\_AES\_192

  Winzip AES-192 encryption.

- ZIP\_EM\_AES\_256

  Winzip AES-256 encryption.

- ZIP\_EM\_TRAD\_PKWARE

  Traditional PKWare encryption. Do not use this method, it is not secure. It is only provided for backwards compatibility.

If *password* is NULL, the default password provided by [zip\_set\_default\_password(3)](/zip_set_default_password/3.md) is used.

The current encryption method for a file in a zip archive can be determined using [zip\_stat(3)](/zip_stat/3.md).

## RETURN VALUES

Upon successful completion 0 is returned. Otherwise, -1 is returned and the error information in *archive* is set to indicate the error.

## ERRORS

**zip\_file\_set\_encryption**() fails if:

- \[ZIP\_ER\_ENCRNOTSUPP\]

  Unsupported compression method requested.

- \[ZIP\_ER\_INVAL\]

  *index* is not a valid file index in *archive*, or the argument combination is invalid.

- \[ZIP\_ER\_MEMORY\]

  Required memory could not be allocated.

- \[ZIP\_ER\_RDONLY\]

  Read-only zip file, no changes allowed.

## SEE ALSO

[libzip(3)](/libzip/3.md), [zip\_encryption\_method\_supported(3)](/zip_encryption_method_supported/3.md), [zip\_fopen\_encrypted(3)](/zip_fopen_encrypted/3.md), [zip\_fopen\_index\_encrypted(3)](/zip_fopen_index_encrypted/3.md), [zip\_set\_default\_password(3)](/zip_set_default_password/3.md), [zip\_stat(3)](/zip_stat/3.md)

## HISTORY

**zip\_file\_set\_encryption**() was added in libzip 1.2.0.

## AUTHORS

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