Difference Between -p and -hp Switches in Unrar

This article explains the core differences between the -p and -hp switches used in RAR and UnRAR command-line utilities. While both switches handle password-protected archives, the key distinction lies in header encryption: -p encrypts only the file contents, leaving metadata like filenames visible, whereas -hp encrypts both the file contents and the archive headers, completely hiding the internal structure until the password is provided.

The -p Switch: Content Encryption

The -p (password) switch is used to specify a password for standard data encryption.

When an archive is created using -p:

  • Only the file data inside the archive is encrypted.
  • Archive headers remain unencrypted and accessible in plain text.
  • Anyone can open or view the archive to see the list of files, directory structures, uncompressed file sizes, and modification dates without entering a password.
  • A password prompt appears only when a user attempts to extract, decompress, or view the actual content of a file.

In unrar, passing -p<password> supplies the decryption key required to unpack these standard encrypted files without an interactive prompt.

The -hp Switch: Header and Content Encryption

The -hp (header password) switch encrypts both the file data and the archive headers.

When an archive is created using -hp:

  • The entire internal structure is protected under encryption.
  • Filenames, extensions, file sizes, and directory structures are completely hidden.
  • Commands like unrar l (list) or attempting to view the archive in a GUI will immediately fail or prompt for a password before showing any file listing at all.
  • Without the correct password, it is impossible to determine what kind of files or how many files the archive contains.

Behavior in UnRAR Extraction

When working with unrar on the command line:

  • Standard Encrypted Archives: Running unrar x -pSECRET archive.rar bypasses the interactive prompt and extracts archives protected with standard data encryption.
  • Header-Encrypted Archives: Running unrar x -hpSECRET archive.rar supplies the key necessary to first unlock the header metadata and then extract the contents.

In many modern versions of unrar, supplying -p<password> will also unlock header-encrypted archives automatically if the password matches. However, using -hp explicitly informs the utility that the header is encrypted, which is essential in automated scripts to prevent hanging or unexpected prompt behavior when processing fully encrypted RAR archives.