package packet

Import Path
	golang.org/x/crypto/openpgp/packet (on go.dev)

Dependency Relation
	imports 36 packages, and imported by one package


Package-Level Type Names (total 44, in which 25 are exported)
/* sort exporteds by: | */
CipherFunction represents the different block ciphers specified for OpenPGP. See http://www.iana.org/assignments/pgp-parameters/pgp-parameters.xhtml#pgp-parameters-13 KeySize returns the key size, in bytes, of cipher. func (*Config).Cipher() CipherFunction func (*SymmetricKeyEncrypted).Decrypt(passphrase []byte) ([]byte, CipherFunction, error) func SerializeEncryptedKey(w io.Writer, pub *PublicKey, cipherFunc CipherFunction, key []byte, config *Config) error func SerializeSymmetricallyEncrypted(w io.Writer, c CipherFunction, key []byte, config *Config) (contents io.WriteCloser, err error) func (*SymmetricallyEncrypted).Decrypt(c CipherFunction, key []byte) (io.ReadCloser, error) const Cipher3DES const CipherAES128 const CipherAES192 const CipherAES256 const CipherCAST5
Compressed represents a compressed OpenPGP packet. The decompressed contents will contain more OpenPGP packets. See RFC 4880, section 5.6. Body io.Reader *T : Packet
CompressionAlgo Represents the different compression algorithms supported by OpenPGP (except for BZIP2, which is not currently supported). See Section 9.3 of RFC 4880. func (*Config).Compression() CompressionAlgo func SerializeCompressed(w io.WriteCloser, algo CompressionAlgo, cc *CompressionConfig) (literaldata io.WriteCloser, err error) const CompressionNone const CompressionZIP const CompressionZLIB
CompressionConfig contains compressor configuration settings. Level is the compression level to use. It must be set to between -1 and 9, with -1 causing the compressor to use the default compression level, 0 causing the compressor to use no compression and 1 to 9 representing increasing (better, slower) compression levels. If Level is less than -1 or more then 9, a non-nil error will be returned during encryption. See the constants above for convenient common settings for Level. func SerializeCompressed(w io.WriteCloser, algo CompressionAlgo, cc *CompressionConfig) (literaldata io.WriteCloser, err error)
Config collects a number of parameters along with sensible defaults. A nil *Config is valid and results in all default values. CompressionConfig configures the compression settings. DefaultCipher is the cipher to be used. If zero, AES-128 is used. DefaultCompressionAlgo is the compression algorithm to be applied to the plaintext before encryption. If zero, no compression is done. DefaultHash is the default hash function to be used. If zero, SHA-256 is used. RSABits is the number of bits in new RSA keys made with NewEntity. If zero, then 2048 bit keys are created. Rand provides the source of entropy. If nil, the crypto/rand Reader is used. S2KCount is only used for symmetric encryption. It determines the strength of the passphrase stretching when the said passphrase is hashed to produce a key. S2KCount should be between 1024 and 65011712, inclusive. If Config is nil or S2KCount is 0, the value 65536 used. Not all values in the above range can be represented. S2KCount will be rounded up to the next representable value if it cannot be encoded exactly. When set, it is strongly encrouraged to use a value that is at least 65536. See RFC 4880 Section 3.7.1.3. Time returns the current time as the number of seconds since the epoch. If Time is nil, time.Now is used. (*T) Cipher() CipherFunction (*T) Compression() CompressionAlgo (*T) Hash() crypto.Hash (*T) Now() time.Time (*T) PasswordHashIterations() int (*T) Random() io.Reader func SerializeEncryptedKey(w io.Writer, pub *PublicKey, cipherFunc CipherFunction, key []byte, config *Config) error func SerializeSymmetricallyEncrypted(w io.Writer, c CipherFunction, key []byte, config *Config) (contents io.WriteCloser, err error) func SerializeSymmetricKeyEncrypted(w io.Writer, passphrase []byte, config *Config) (key []byte, err error) func (*EncryptedKey).Decrypt(priv *PrivateKey, config *Config) error func (*Signature).Sign(h hash.Hash, priv *PrivateKey, config *Config) (err error) func (*Signature).SignKey(pub *PublicKey, priv *PrivateKey, config *Config) error func (*Signature).SignUserId(id string, pub *PublicKey, priv *PrivateKey, config *Config) error func golang.org/x/crypto/openpgp.ArmoredDetachSign(w io.Writer, signer *openpgp.Entity, message io.Reader, config *Config) (err error) func golang.org/x/crypto/openpgp.ArmoredDetachSignText(w io.Writer, signer *openpgp.Entity, message io.Reader, config *Config) error func golang.org/x/crypto/openpgp.DetachSign(w io.Writer, signer *openpgp.Entity, message io.Reader, config *Config) error func golang.org/x/crypto/openpgp.DetachSignText(w io.Writer, signer *openpgp.Entity, message io.Reader, config *Config) error func golang.org/x/crypto/openpgp.Encrypt(ciphertext io.Writer, to []*openpgp.Entity, signed *openpgp.Entity, hints *openpgp.FileHints, config *Config) (plaintext io.WriteCloser, err error) func golang.org/x/crypto/openpgp.NewEntity(name, comment, email string, config *Config) (*openpgp.Entity, error) func golang.org/x/crypto/openpgp.ReadMessage(r io.Reader, keyring openpgp.KeyRing, prompt openpgp.PromptFunction, config *Config) (md *openpgp.MessageDetails, err error) func golang.org/x/crypto/openpgp.Sign(output io.Writer, signed *openpgp.Entity, hints *openpgp.FileHints, config *Config) (input io.WriteCloser, err error) func golang.org/x/crypto/openpgp.SymmetricallyEncrypt(ciphertext io.Writer, passphrase []byte, hints *openpgp.FileHints, config *Config) (plaintext io.WriteCloser, err error) func golang.org/x/crypto/openpgp.(*Entity).SerializePrivate(w io.Writer, config *Config) (err error) func golang.org/x/crypto/openpgp.(*Entity).SignIdentity(identity string, signer *openpgp.Entity, config *Config) error
EncryptedKey represents a public-key encrypted session key. See RFC 4880, section 5.1. Algo PublicKeyAlgorithm // only valid after a successful Decrypt // only valid after a successful Decrypt KeyId uint64 Decrypt decrypts an encrypted session key with the given private key. The private key must have been decrypted first. If config is nil, sensible defaults will be used. Serialize writes the encrypted key packet, e, to w. *T : Packet
LiteralData represents an encrypted file. See RFC 4880, section 5.9. Body io.Reader FileName string IsBinary bool // Unix epoch time. Either creation time or modification time. 0 means undefined. ForEyesOnly returns whether the contents of the LiteralData have been marked as especially sensitive. *T : Packet
An OCFBResyncOption determines if the "resynchronization step" of OCFB is performed. func NewOCFBDecrypter(block cipher.Block, prefix []byte, resync OCFBResyncOption) cipher.Stream func NewOCFBEncrypter(block cipher.Block, randData []byte, resync OCFBResyncOption) (cipher.Stream, []byte) const OCFBNoResync const OCFBResync
OnePassSignature represents a one-pass signature packet. See RFC 4880, section 5.4. Hash crypto.Hash IsLast bool KeyId uint64 PubKeyAlgo PublicKeyAlgorithm SigType SignatureType Serialize marshals the given OnePassSignature to w. *T : Packet
OpaquePacket represents an OpenPGP packet as raw, unparsed data. This is useful for splitting and storing the original packet contents separately, handling unsupported packet types or accessing parts of the packet not yet implemented by this package. Binary contents of the packet data Reason why the packet was parsed opaquely Packet type Parse attempts to parse the opaque contents into a structure supported by this package. If the packet is not known then the result will be another OpaquePacket. Serialize marshals the packet to a writer in its original form, including the packet header. *T : Packet func (*OpaqueReader).Next() (op *OpaquePacket, err error)
OpaqueReader reads OpaquePackets from an io.Reader. Read the next OpaquePacket. func NewOpaqueReader(r io.Reader) *OpaqueReader
OpaqueSubpacket represents an unparsed OpenPGP subpacket, as found in signature and user attribute packets. Contents []byte SubType uint8 (*T) Serialize(w io.Writer) (err error) func OpaqueSubpackets(contents []byte) (result []*OpaqueSubpacket, err error) func NewUserAttribute(contents ...*OpaqueSubpacket) *UserAttribute
Packet represents an OpenPGP packet. Users are expected to try casting instances of this interface to specific packet types. *Compressed *EncryptedKey *LiteralData *OnePassSignature *OpaquePacket *PrivateKey *PublicKey *PublicKeyV3 *Signature *SignatureV3 *SymmetricallyEncrypted *SymmetricKeyEncrypted *UserAttribute *UserId func Read(r io.Reader) (p Packet, err error) func (*OpaquePacket).Parse() (p Packet, err error) func (*Reader).Next() (p Packet, err error) func (*Reader).Unread(p Packet)
PrivateKey represents a possibly encrypted private key. See RFC 4880, section 5.5.3. // if true then the private key is unavailable until Decrypt has been called. // An *{rsa|dsa|ecdsa}.PrivateKey or crypto.Signer/crypto.Decrypter (Decryptor RSA only). PublicKey PublicKey PublicKey.CreationTime time.Time PublicKey.Fingerprint [20]byte PublicKey.IsSubkey bool PublicKey.KeyId uint64 PublicKey.PubKeyAlgo PublicKeyAlgorithm BitLength returns the bit length for the given public key. CanSign returns true iff this public key can generate signatures Decrypt decrypts an encrypted private key using a passphrase. KeyIdShortString returns the short form of public key's fingerprint in capital hex, as shown by gpg --list-keys (e.g. "621CC013"). KeyIdString returns the public key's fingerprint in capital hex (e.g. "6C7EE1B8621CC013"). (*T) Serialize(w io.Writer) (err error) SerializeSignaturePrefix writes the prefix for this public key to the given Writer. The prefix is used when calculating a signature over this public key. See RFC 4880, section 5.2.4. VerifyKeySignature returns nil iff sig is a valid signature, made by this public key, of signed. VerifyRevocationSignature returns nil iff sig is a valid signature, made by this public key. VerifySignature returns nil iff sig is a valid signature, made by this public key, of the data hashed into signed. signed is mutated by this call. VerifySignatureV3 returns nil iff sig is a valid signature, made by this public key, of the data hashed into signed. signed is mutated by this call. VerifyUserIdSignature returns nil iff sig is a valid signature, made by this public key, that id is the identity of pub. VerifyUserIdSignatureV3 returns nil iff sig is a valid signature, made by this public key, that id is the identity of pub. *T : Packet func NewDSAPrivateKey(creationTime time.Time, priv *dsa.PrivateKey) *PrivateKey func NewECDSAPrivateKey(creationTime time.Time, priv *ecdsa.PrivateKey) *PrivateKey func NewElGamalPrivateKey(creationTime time.Time, priv *elgamal.PrivateKey) *PrivateKey func NewRSAPrivateKey(creationTime time.Time, priv *rsa.PrivateKey) *PrivateKey func NewSignerPrivateKey(creationTime time.Time, signer crypto.Signer) *PrivateKey func (*EncryptedKey).Decrypt(priv *PrivateKey, config *Config) error func (*Signature).Sign(h hash.Hash, priv *PrivateKey, config *Config) (err error) func (*Signature).SignKey(pub *PublicKey, priv *PrivateKey, config *Config) error func (*Signature).SignUserId(id string, pub *PublicKey, priv *PrivateKey, config *Config) error
PublicKey represents an OpenPGP public key. See RFC 4880, section 5.5.2. CreationTime time.Time Fingerprint [20]byte IsSubkey bool KeyId uint64 PubKeyAlgo PublicKeyAlgorithm // *rsa.PublicKey, *dsa.PublicKey or *ecdsa.PublicKey BitLength returns the bit length for the given public key. CanSign returns true iff this public key can generate signatures KeyIdShortString returns the short form of public key's fingerprint in capital hex, as shown by gpg --list-keys (e.g. "621CC013"). KeyIdString returns the public key's fingerprint in capital hex (e.g. "6C7EE1B8621CC013"). (*T) Serialize(w io.Writer) (err error) SerializeSignaturePrefix writes the prefix for this public key to the given Writer. The prefix is used when calculating a signature over this public key. See RFC 4880, section 5.2.4. VerifyKeySignature returns nil iff sig is a valid signature, made by this public key, of signed. VerifyRevocationSignature returns nil iff sig is a valid signature, made by this public key. VerifySignature returns nil iff sig is a valid signature, made by this public key, of the data hashed into signed. signed is mutated by this call. VerifySignatureV3 returns nil iff sig is a valid signature, made by this public key, of the data hashed into signed. signed is mutated by this call. VerifyUserIdSignature returns nil iff sig is a valid signature, made by this public key, that id is the identity of pub. VerifyUserIdSignatureV3 returns nil iff sig is a valid signature, made by this public key, that id is the identity of pub. *T : Packet func NewDSAPublicKey(creationTime time.Time, pub *dsa.PublicKey) *PublicKey func NewECDSAPublicKey(creationTime time.Time, pub *ecdsa.PublicKey) *PublicKey func NewElGamalPublicKey(creationTime time.Time, pub *elgamal.PublicKey) *PublicKey func NewRSAPublicKey(creationTime time.Time, pub *rsa.PublicKey) *PublicKey func SerializeEncryptedKey(w io.Writer, pub *PublicKey, cipherFunc CipherFunction, key []byte, config *Config) error func (*PublicKey).VerifyKeySignature(signed *PublicKey, sig *Signature) error func (*PublicKey).VerifyUserIdSignature(id string, pub *PublicKey, sig *Signature) (err error) func (*PublicKey).VerifyUserIdSignatureV3(id string, pub *PublicKey, sig *SignatureV3) (err error) func (*Signature).SignKey(pub *PublicKey, priv *PrivateKey, config *Config) error func (*Signature).SignUserId(id string, pub *PublicKey, priv *PrivateKey, config *Config) error
PublicKeyAlgorithm represents the different public key system specified for OpenPGP. See http://www.iana.org/assignments/pgp-parameters/pgp-parameters.xhtml#pgp-parameters-12 CanEncrypt returns true if it's possible to encrypt a message to a public key of the given type. CanSign returns true if it's possible for a public key of the given type to sign a message. const PubKeyAlgoDSA const PubKeyAlgoECDH const PubKeyAlgoECDSA const PubKeyAlgoElGamal const PubKeyAlgoRSA const PubKeyAlgoRSAEncryptOnly const PubKeyAlgoRSASignOnly
PublicKeyV3 represents older, version 3 public keys. These keys are less secure and should not be used for signing or encrypting. They are supported here only for parsing version 3 key material and validating signatures. See RFC 4880, section 5.5.2. CreationTime time.Time DaysToExpire uint16 Fingerprint [16]byte IsSubkey bool KeyId uint64 PubKeyAlgo PublicKeyAlgorithm PublicKey *rsa.PublicKey BitLength returns the bit length for the given public key. CanSign returns true iff this public key can generate signatures KeyIdShortString returns the short form of public key's fingerprint in capital hex, as shown by gpg --list-keys (e.g. "621CC013"). KeyIdString returns the public key's fingerprint in capital hex (e.g. "6C7EE1B8621CC013"). (*T) Serialize(w io.Writer) (err error) SerializeSignaturePrefix writes the prefix for this public key to the given Writer. The prefix is used when calculating a signature over this public key. See RFC 4880, section 5.2.4. VerifyKeySignatureV3 returns nil iff sig is a valid signature, made by this public key, of signed. VerifySignatureV3 returns nil iff sig is a valid signature, made by this public key, of the data hashed into signed. signed is mutated by this call. VerifyUserIdSignatureV3 returns nil iff sig is a valid signature, made by this public key, that id is the identity of pub. *T : Packet func (*PublicKeyV3).VerifyKeySignatureV3(signed *PublicKeyV3, sig *SignatureV3) (err error) func (*PublicKeyV3).VerifyUserIdSignatureV3(id string, pub *PublicKeyV3, sig *SignatureV3) (err error)
Reader reads packets from an io.Reader and allows packets to be 'unread' so that they result from the next call to Next. Next returns the most recently unread Packet, or reads another packet from the top-most io.Reader. Unknown packet types are skipped. Push causes the Reader to start reading from a new io.Reader. When an EOF error is seen from the new io.Reader, it is popped and the Reader continues to read from the next most recent io.Reader. Push returns a StructuralError if pushing the reader would exceed the maximum recursion level, otherwise it returns nil. Unread causes the given Packet to be returned from the next call to Next. func NewReader(r io.Reader) *Reader func golang.org/x/crypto/openpgp.ReadEntity(packets *Reader) (*openpgp.Entity, error)
Signature represents a signature. See RFC 4880, section 5.2. CreationTime time.Time DSASigR parsedMPI DSASigS parsedMPI ECDSASigR parsedMPI ECDSASigS parsedMPI EmbeddedSignature, if non-nil, is a signature of the parent key, by this key. This prevents an attacker from claiming another's signing subkey as their own. FlagCertify bool FlagEncryptCommunications bool FlagEncryptStorage bool FlagSign bool FlagsValid is set if any flags were given. See RFC 4880, section 5.2.3.21 for details. Hash crypto.Hash HashSuffix is extra data that is hashed in after the signed data. HashTag contains the first two bytes of the hash for fast rejection of bad signed data. IsPrimaryId *bool IssuerKeyId *uint64 KeyLifetimeSecs *uint32 MDC is set if this signature has a feature packet that indicates support for MDC subpackets. PreferredCompression []uint8 PreferredHash []uint8 PreferredSymmetric []uint8 PubKeyAlgo PublicKeyAlgorithm RSASignature parsedMPI RevocationReason is set if this signature has been revoked. See RFC 4880, section 5.2.3.23 for details. RevocationReasonText string SigLifetimeSecs *uint32 SigType SignatureType KeyExpired returns whether sig is a self-signature of a key that has expired. Serialize marshals sig to w. Sign, SignUserId or SignKey must have been called first. Sign signs a message with a private key. The hash, h, must contain the hash of the message to be signed and will be mutated by this function. On success, the signature is stored in sig. Call Serialize to write it out. If config is nil, sensible defaults will be used. SignKey computes a signature from priv, asserting that pub is a subkey. On success, the signature is stored in sig. Call Serialize to write it out. If config is nil, sensible defaults will be used. SignUserId computes a signature from priv, asserting that pub is a valid key for the identity id. On success, the signature is stored in sig. Call Serialize to write it out. If config is nil, sensible defaults will be used. *T : Packet func (*PublicKey).VerifyKeySignature(signed *PublicKey, sig *Signature) error func (*PublicKey).VerifyRevocationSignature(sig *Signature) (err error) func (*PublicKey).VerifySignature(signed hash.Hash, sig *Signature) (err error) func (*PublicKey).VerifyUserIdSignature(id string, pub *PublicKey, sig *Signature) (err error)
SignatureType represents the different semantic meanings of an OpenPGP signature. See RFC 4880, section 5.2.1. const SigTypeBinary
SignatureV3 represents older version 3 signatures. These signatures are less secure than version 4 and should not be used to create new signatures. They are included here for backwards compatibility to read and validate with older key material. See RFC 4880, section 5.2.2. CreationTime time.Time DSASigR parsedMPI DSASigS parsedMPI Hash crypto.Hash HashTag [2]byte IssuerKeyId uint64 PubKeyAlgo PublicKeyAlgorithm RSASignature parsedMPI SigType SignatureType Serialize marshals sig to w. Sign, SignUserId or SignKey must have been called first. *T : Packet func (*PublicKey).VerifySignatureV3(signed hash.Hash, sig *SignatureV3) (err error) func (*PublicKey).VerifyUserIdSignatureV3(id string, pub *PublicKey, sig *SignatureV3) (err error) func (*PublicKeyV3).VerifyKeySignatureV3(signed *PublicKeyV3, sig *SignatureV3) (err error) func (*PublicKeyV3).VerifySignatureV3(signed hash.Hash, sig *SignatureV3) (err error) func (*PublicKeyV3).VerifyUserIdSignatureV3(id string, pub *PublicKeyV3, sig *SignatureV3) (err error)
SymmetricallyEncrypted represents a symmetrically encrypted byte string. The encrypted contents will consist of more OpenPGP packets. See RFC 4880, sections 5.7 and 5.13. // true iff this is a type 18 packet and thus has an embedded MAC. Decrypt returns a ReadCloser, from which the decrypted contents of the packet can be read. An incorrect key can, with high probability, be detected immediately and this will result in a KeyIncorrect error being returned. *T : Packet
SymmetricKeyEncrypted represents a passphrase protected session key. See RFC 4880, section 5.3. CipherFunc CipherFunction Decrypt attempts to decrypt an encrypted session key and returns the key and the cipher to use when decrypting a subsequent Symmetrically Encrypted Data packet. *T : Packet
UserAttribute is capable of storing other types of data about a user beyond name, email and a text comment. In practice, user attributes are typically used to store a signed thumbnail photo JPEG image of the user. See RFC 4880, section 5.12. Contents []*OpaqueSubpacket ImageData returns zero or more byte slices, each containing JPEG File Interchange Format (JFIF), for each photo in the user attribute packet. Serialize marshals the user attribute to w in the form of an OpenPGP packet, including header. *T : Packet func NewUserAttribute(contents ...*OpaqueSubpacket) *UserAttribute func NewUserAttributePhoto(photos ...image.Image) (uat *UserAttribute, err error)
UserId contains text that is intended to represent the name and email address of the key holder. See RFC 4880, section 5.11. By convention, this takes the form "Full Name (Comment) <email@example.com>" Comment string Email string // By convention, this takes the form "Full Name (Comment) <email@example.com>" which is split out in the fields below. Name string Serialize marshals uid to w in the form of an OpenPGP packet, including header. *T : Packet func NewUserId(name, comment, email string) *UserId
Package-Level Functions (total 60, in which 23 are exported)
NewDSAPublicKey returns a PublicKey that wraps the given dsa.PublicKey.
NewElGamalPublicKey returns a PublicKey that wraps the given elgamal.PublicKey.
NewOCFBDecrypter returns a cipher.Stream which decrypts data with OpenPGP's cipher feedback mode using the given cipher.Block. Prefix must be the first blockSize + 2 bytes of the ciphertext, where blockSize is the cipher.Block's block size. If an incorrect key is detected then nil is returned. On successful exit, blockSize+2 bytes of decrypted data are written into prefix. Resync determines if the "resynchronization step" from RFC 4880, 13.9 step 7 is performed. Different parts of OpenPGP vary on this point.
NewOCFBEncrypter returns a cipher.Stream which encrypts data with OpenPGP's cipher feedback mode using the given cipher.Block, and an initial amount of ciphertext. randData must be random bytes and be the same length as the cipher.Block's block size. Resync determines if the "resynchronization step" from RFC 4880, 13.9 step 7 is performed. Different parts of OpenPGP vary on this point.
NewRSAPublicKey returns a PublicKey that wraps the given rsa.PublicKey.
NewSignerPrivateKey creates a PrivateKey from a crypto.Signer that implements RSA or ECDSA.
NewUserAttribute creates a new user attribute packet containing the given subpackets.
NewUserAttributePhoto creates a user attribute packet containing the given images.
NewUserId returns a UserId or nil if any of the arguments contain invalid characters. The invalid characters are '\x00', '(', ')', '<' and '>'
OpaqueSubpackets extracts opaque, unparsed OpenPGP subpackets from their byte representation.
Read reads a single OpenPGP packet from the given io.Reader. If there is an error parsing a packet, the whole packet is consumed from the input.
SerializeCompressed serializes a compressed data packet to w and returns a WriteCloser to which the literal data packets themselves can be written and which MUST be closed on completion. If cc is nil, sensible defaults will be used to configure the compression algorithm.
SerializeEncryptedKey serializes an encrypted key packet to w that contains key, encrypted to pub. If config is nil, sensible defaults will be used.
SerializeLiteral serializes a literal data packet to w and returns a WriteCloser to which the data itself can be written and which MUST be closed on completion. The fileName is truncated to 255 bytes.
SerializeSymmetricallyEncrypted serializes a symmetrically encrypted packet to w and returns a WriteCloser to which the to-be-encrypted packets can be written. If config is nil, sensible defaults will be used.
SerializeSymmetricKeyEncrypted serializes a symmetric key packet to w. The packet contains a random session key, encrypted by a key derived from the given passphrase. The session key is returned and must be passed to SerializeSymmetricallyEncrypted. If config is nil, sensible defaults will be used.
Package-Level Variables (total 3, none are exported)
Package-Level Constants (total 73, in which 37 are exported)
See RFC 4880, section 5.2.3.21 for details.
RFC 6637, Section 5.
Deprecated in RFC 4880, Section 13.5. Use key flags instead.