crypt

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package crypt implements the PDF /Standard security handler for versions V2 (RC4), V4 (RC4 or AES-128) and V5 (AES-256, PDF 1.7 Extension 3 and PDF 2.0).

Only password-based access (the user password "empty string" path included) is supported. Public-key encryption (/Adobe.PubSec) is out of scope.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Algorithm

type Algorithm int

Algorithm identifies a stream/string cipher.

const (
	AlgRC4 Algorithm = iota + 1
	AlgAES128
	AlgAES256
	AlgIdentity
)

type Handler

type Handler struct {
	V          int       // /V version
	R          int       // /R revision
	Length     int       // key length in bits (V2/V4)
	FileKey    []byte    // file encryption key (computed from password)
	StringAlg  Algorithm // algorithm for strings
	StreamAlg  Algorithm // algorithm for streams
	EmbedAlg   Algorithm // algorithm for embedded files
	CryptFilts map[string]filterDef
	StmF       string // default stream filter (V4)
	StrF       string // default string filter (V4)
	EFF        string // embedded-file filter (V4)
}

Handler holds the state needed to decrypt strings and streams in a PDF once a password has been validated.

func New

func New(p Params, password []byte) (*Handler, error)

New tries to instantiate a Handler given the encryption parameters and the user password (empty string is the most common case).

func (*Handler) DecryptStream

func (h *Handler) DecryptStream(data []byte, objNum, objGen int, cryptFilterName string) ([]byte, error)

DecryptStream decrypts a stream. cryptFilterName, if non-empty, overrides the default stream algorithm (V4 streams can carry an inline /Filter chain containing /Crypt with parameters).

func (*Handler) DecryptString

func (h *Handler) DecryptString(data []byte, objNum, objGen int) ([]byte, error)

DecryptString decrypts a string using the configured string algorithm and object identity.

type Params

type Params struct {
	V            int
	R            int
	Length       int
	P            int32
	OwnerEntry   []byte // /O
	UserEntry    []byte // /U
	OE           []byte // /OE (V5)
	UE           []byte // /UE (V5)
	Perms        []byte // /Perms (V5)
	ID0          []byte // first element of /ID
	EncryptMeta  bool
	StmF         string
	StrF         string
	EFF          string
	CryptFilters map[string]string // name → CFM
}

Params is the inputs needed to instantiate a Handler from the PDF /Encrypt dict.

Jump to

Keyboard shortcuts

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