View Source Pdf.Reader.Encryption.PasswordPad (ExPDF v1.0.1)

Provides the canonical 32-byte PDF password-padding constant and a helper to pad (or truncate) an arbitrary password binary to exactly 32 bytes.

The padding constant is defined verbatim in the PDF specification and is used in Algorithm 2 (file encryption key derivation) as well as Algorithms 3–5 (owner/user password authentication) for Standard Security Handler revisions R=2 through R=4.

Usage

padded = PasswordPad.pad(user_supplied_password)
# padded is always exactly 32 bytes

Spec references

Summary

Functions

Returns the canonical 32-byte PDF password-padding constant.

Pads or truncates password to exactly 32 bytes per PDF 1.7 § 7.6.3.3.

Functions

@spec constant() :: <<_::256>>

Returns the canonical 32-byte PDF password-padding constant.

Defined in PDF 1.7 § 7.6.3.3 as a fixed magic value used to pad short passwords before they are fed into MD5 hashing.

@spec pad(binary()) :: <<_::256>>

Pads or truncates password to exactly 32 bytes per PDF 1.7 § 7.6.3.3.

  • If password is shorter than 32 bytes: appends bytes from @pad_constant until the result is 32 bytes long.
  • If password is exactly 32 bytes: returns it unchanged.
  • If password is longer than 32 bytes: truncates to the first 32 bytes.