security

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decryptor

type Decryptor interface {
	// DecryptString decrypts an encrypted string. ref is the indirect object reference (object number, generation).
	DecryptString(ref model.Ref, ciphertext []byte) ([]byte, error)
	// DecryptStream decrypts an encrypted stream. ref is the indirect object reference.
	DecryptStream(ref model.Ref, ciphertext []byte) ([]byte, error)
}

Decryptor decrypts PDF strings and streams for a given object reference.

func NewAES256Decryptor

func NewAES256Decryptor(encryptDict model.Dict, id model.Array, userPassword string) (Decryptor, error)

NewAES256Decryptor constructs a decryptor from the Encrypt dict and trailer ID using the same PBKDF2-SHA256 scheme as BuildAES256EncryptDictForWrite.

func NewStandardDecryptor

func NewStandardDecryptor(encryptDict model.Dict, id model.Array, userPassword string) (Decryptor, error)

NewStandardDecryptor builds a decryptor from the Encrypt dict, trailer ID, and user password. Supports R=2 and R=3 (RC4), R=4 (AES-128 or RC4 per CF dict), R=5 (AES-256, PDF 1.7 ext 3), and R=6 (AES-256, PDF 2.0).

type Encryptor

type Encryptor interface {
	EncryptString(ref model.Ref, plaintext []byte) ([]byte, error)
	EncryptStream(ref model.Ref, plaintext []byte) ([]byte, error)
}

Encryptor encrypts PDF strings and streams for a given object reference (used when writing).

func BuildAES256EncryptDictForWrite

func BuildAES256EncryptDictForWrite(userPassword, ownerPassword string, id []byte, P int32) (model.Dict, Encryptor, error)

BuildAES256EncryptDictForWrite creates an Encrypt dictionary and Encryptor for AES-256.

func BuildEncryptDictForWrite

func BuildEncryptDictForWrite(userPassword, ownerPassword string, id []byte, P int32) (model.Dict, Encryptor, error)

BuildEncryptDictForWrite creates an Encrypt dictionary and an Encryptor for writing (Standard, R=2). id is the first element of the trailer /ID array (e.g. 16 bytes); if nil, a zero slice is used for key derivation. P is the permission flags (e.g. -4 for allow all).

type StandardDecryptor

type StandardDecryptor struct {
	// contains filtered or unexported fields
}

StandardDecryptor implements Decryptor for PDF Standard security handler (R=2, R=3).

func (*StandardDecryptor) DecryptStream

func (d *StandardDecryptor) DecryptStream(ref model.Ref, ciphertext []byte) ([]byte, error)

func (*StandardDecryptor) DecryptString

func (d *StandardDecryptor) DecryptString(ref model.Ref, ciphertext []byte) ([]byte, error)

func (*StandardDecryptor) EncryptStream

func (d *StandardDecryptor) EncryptStream(ref model.Ref, plaintext []byte) ([]byte, error)

EncryptStream encrypts plaintext (RC4 is symmetric).

func (*StandardDecryptor) EncryptString

func (d *StandardDecryptor) EncryptString(ref model.Ref, plaintext []byte) ([]byte, error)

EncryptString encrypts plaintext (RC4 is symmetric).

Jump to

Keyboard shortcuts

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