encrypt

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeUValue

func ComputeUValue(encryptKey []byte, encrypt *types.PDFEncryption, fileID []byte, verbose bool) ([]byte, error)

ComputeUValue computes the U value for password verification For revision 4 (AES), the U value is 48 bytes: 32-byte hash + 16-byte validation salt Algorithm 5 from ISO 32000-1:2008

func ComputeUValueV5

func ComputeUValueV5(password []byte, passwordKey []byte, encrypt *types.PDFEncryption, fileID []byte, verbose bool) ([]byte, error)

ComputeUValueV5 computes the U value for V5/R5/R6 password verification Based on ISO 32000-2 section 7.6.4.4.9 - uses SHA-256 and AES-128 This function computes the U value from a password for verification purposes. The actual password (not the derived key) is required for proper verification.

func DecryptObject

func DecryptObject(objBytes []byte, objNum, genNum int, encrypt *types.PDFEncryption) ([]byte, error)

DecryptObject decrypts a single PDF object or stream Algorithm 1 from ISO 32000-1:2008 Implementation copied EXACTLY from PyPDF's _make_crypt_filter (lines 914-935) and CryptAES.decrypt (lines 73-88)

func DecryptPDF

func DecryptPDF(pdfBytes []byte, password []byte, verbose bool) ([]byte, *types.PDFEncryption, error)

DecryptPDF decrypts a PDF using the provided password Returns decrypted PDF bytes and encryption info Note: Implementation inspired by UniPDF but written from first principles

func DecryptPDFObjects

func DecryptPDFObjects(pdfBytes []byte, encrypt *types.PDFEncryption, verbose bool) ([]byte, error)

DecryptPDFObjects decrypts all encrypted objects in the PDF This is a simplified version - full implementation would parse xref table and decrypt objects individually

func DeriveEncryptionKey

func DeriveEncryptionKey(password []byte, encrypt *types.PDFEncryption, fileID []byte, verbose bool) ([]byte, error)

DeriveEncryptionKey derives the encryption key from password Based on PDF encryption algorithm (ISO 32000) - Algorithm 2 (V1-V4) or 7.6.4.3.3 (V5+)

func DeriveEncryptionKeyV5

func DeriveEncryptionKeyV5(password []byte, encrypt *types.PDFEncryption, fileID []byte, verbose bool) ([]byte, error)

DeriveEncryptionKeyV5 derives the encryption key for V5/R5/R6 (AES-256) Based on ISO 32000-2 section 7.6.4.3.3 - SHA-256 based key derivation

func DeriveOwnerKey

func DeriveOwnerKey(ownerPassword []byte, encrypt *types.PDFEncryption, fileID []byte, verbose bool) ([]byte, error)

DeriveOwnerKey derives the encryption key from owner password Algorithm 3 from ISO 32000-1:2008 (V1-V4) or V5 algorithm (V5+)

func DeriveOwnerKeyV5

func DeriveOwnerKeyV5(ownerPassword []byte, encrypt *types.PDFEncryption, fileID []byte, verbose bool) ([]byte, error)

DeriveOwnerKeyV5 derives the owner password key for V5/R5/R6 Similar to DeriveEncryptionKeyV5 but uses owner password

func DeriveUserKeyFromOwner

func DeriveUserKeyFromOwner(ownerKey []byte, encrypt *types.PDFEncryption, verbose bool) ([]byte, error)

DeriveUserKeyFromOwner derives the user encryption key from owner key

func ExtractFileID

func ExtractFileID(pdfBytes []byte, verbose bool) []byte

ExtractFileID extracts the file ID from PDF trailer Returns the first element of the ID array (ID[0]) File ID can be in hex format: <7FB157EB...> or binary: (binary data)

func ParseEncryptionDictionary

func ParseEncryptionDictionary(pdfBytes []byte, verbose bool) (*types.PDFEncryption, error)

ParseEncryptionDictionary parses the /Encrypt dictionary from PDF

func UnwrapOwnerKeyV5

func UnwrapOwnerKeyV5(ownerPasswordKey []byte, encrypt *types.PDFEncryption, verbose bool) ([]byte, error)

UnwrapOwnerKeyV5 unwraps the owner encryption key from /OE Similar to UnwrapUserKeyV5 but uses owner password derived key

func UnwrapUserKeyV5

func UnwrapUserKeyV5(passwordKey []byte, encrypt *types.PDFEncryption, verbose bool) ([]byte, error)

UnwrapUserKeyV5 unwraps the user encryption key from /UE using the password-derived key Based on ISO 32000-2 - uses AES-128 in ECB mode for key unwrapping

func VerifyUValueV5

func VerifyUValueV5(password []byte, passwordKey []byte, encrypt *types.PDFEncryption, fileID []byte, verbose bool) (bool, error)

VerifyUValueV5 verifies a password by comparing computed U value with stored U value Returns true if password is correct, false otherwise

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL