HomeUniDoc
...

Package crypt

Overview ▾

type Filter

Filter is a common interface for crypt filter methods.

type Filter interface {
    // Name returns a name of the filter that should be used in CFM field of Encrypt dictionary.
    Name() string
    // KeyLength returns a length of the encryption key in bytes.
    KeyLength() int
    // PDFVersion reports the minimal version of PDF document that introduced this filter.
    PDFVersion() [2]int
    // HandlerVersion reports V and R parameters that should be used for this filter.
    HandlerVersion() (V, R int)
    // MakeKey generates a object encryption key based on file encryption key and object numbers.
    // Used only for legacy filters - AESV3 doesn't change the key for each object.
    MakeKey(objNum, genNum uint32, fkey []byte) ([]byte, error)
    // EncryptBytes encrypts a buffer using object encryption key, as returned by MakeKey.
    // Implementation may reuse a buffer and encrypt data in-place.
    EncryptBytes(p []byte, okey []byte) ([]byte, error)
    // DecryptBytes decrypts a buffer using object encryption key, as returned by MakeKey.
    // Implementation may reuse a buffer and decrypt data in-place.
    DecryptBytes(p []byte, okey []byte) ([]byte, error)
}

func NewFilter

func NewFilter(d FilterDict) (Filter, error)

NewFilter creates CryptFilter from a corresponding dictionary.

func NewFilterAESV2

func NewFilterAESV2() Filter

NewFilterAESV2 creates an AES-based filter with a 128 bit key (AESV2).

func NewFilterAESV3

func NewFilterAESV3() Filter

NewFilterAESV3 creates an AES-based filter with a 256 bit key (AESV3).

func NewFilterV2

func NewFilterV2(length int) Filter

NewFilterV2 creates a RC4-based filter with a specified key length (in bytes).

func NewIdentity

func NewIdentity() Filter

NewIdentity creates an identity filter that bypasses all data without changes.

type FilterDict

FilterDict represents information from a CryptFilter dictionary.

type FilterDict struct {
    CFM       string // The method used, if any, by the PDF reader to decrypt data.
    AuthEvent security.AuthEvent
    Length    int // in bytes
}