pgp

package
v0.1.23 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package pgp encrypts, signs, decrypts and verifies OpenPGP messages (RFC 9580, and RFC 4880 for older peers), for payers, clearinghouses and state agencies that exchange files over SFTP or email under PGP.

The cryptography is github.com/ProtonMail/go-crypto, the maintained fork of golang.org/x/crypto/openpgp; nothing here implements a primitive. This package only loads keys and decides what a message must carry.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Describe

func Describe(e *openpgp.Entity) string

Describe names a key by its first user id and fingerprint.

func IsPGP

func IsPGP(data []byte) bool

IsPGP reports whether data looks like an OpenPGP message, armored or binary.

func KeyID

func KeyID(e *openpgp.Entity) string

KeyID is a key's fingerprint in upper-case hex, as gpg prints it.

func ParseKeys

func ParseKeys(b []byte) (openpgp.EntityList, error)

ParseKeys reads armored or binary keys.

func ReadKeys

func ReadKeys(path string) (openpgp.EntityList, error)

ReadKeys reads armored or binary keys from a file: a public key ring, a secret key, or several concatenated.

func Seal

func Seal(data []byte, o SealOptions) ([]byte, error)

Seal encrypts (and optionally signs) data. With no recipients and a signer it writes a signed message only.

func Unlock

func Unlock(list openpgp.EntityList, passphrase []byte) error

Unlock decrypts every secret key and subkey in list with passphrase. Keys that are not protected are left as they are.

Types

type OpenOptions

type OpenOptions struct {
	// Keys are our unlocked secret keys, for decrypting.
	Keys openpgp.EntityList
	// Verify are the senders' public keys a signature is checked against.
	Verify openpgp.EntityList
	// RequireSignature refuses a message not signed by one of Verify.
	RequireSignature bool
	// AllowUnencrypted accepts a message that is signed but not encrypted.
	AllowUnencrypted bool
}

OpenOptions says what an incoming message needs.

type Opened

type Opened struct {
	Data      []byte
	FileName  string
	Encrypted bool
	// SignedBy is the verified signer, or "" when the message was not signed by a known key.
	SignedBy string
}

Opened is what an incoming message held.

func Open

func Open(data []byte, o OpenOptions) (*Opened, error)

Open decrypts and verifies a message.

type SealOptions

type SealOptions struct {
	// To are the recipients' public keys; the message is readable by any of them.
	To openpgp.EntityList
	// Signer, when set, signs the message (an unlocked secret key).
	Signer *openpgp.Entity
	// Armor writes ASCII armor ("-----BEGIN PGP MESSAGE-----") rather than binary.
	Armor bool
	// FileName is the literal data packet's file name, which some receivers use to name what they decrypt.
	FileName string
	// Compress compresses before encrypting (ZLIB), as gpg does by default.
	Compress bool
}

SealOptions says how to protect an outgoing message.

Jump to

Keyboard shortcuts

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