Top Description Fields Constructors Methods
org.bouncycastle.openpgp

public Class PGPSignature

extends PGPDefaultSignatureGenerator
Class Inheritance
Imports
java.io.ByteArrayOutputStream, .IOException, .OutputStream, java.util.ArrayList, .Date, .List, org.bouncycastle.asn1.ASN1EncodableVector, .ASN1Integer, .DERSequence, org.bouncycastle.bcpg.BCPGInputStream, .BCPGOutputStream, .HashUtils, .KeyIdentifier, .MPInteger, .Packet, .PublicKeyAlgorithmTags, .PublicKeyPacket, .SignaturePacket, .SignatureSubpacket, .TrustPacket, org.bouncycastle.bcpg.sig.IssuerFingerprint, .IssuerKeyID, org.bouncycastle.math.ec.rfc8032.Ed25519, .Ed448, org.bouncycastle.openpgp.operator.PGPContentVerifier, .PGPContentVerifierBuilder, .PGPContentVerifierBuilderProvider, org.bouncycastle.util.Arrays, .BigIntegers, .Strings

A PGP signature object.

Field Summary

Modifier and TypeField and Description
public static final int
BINARY_DOCUMENT

The signature is made over some binary data.

public static final int
CANONICAL_TEXT_DOCUMENT

The signature is made over text data.

public static final int
CASUAL_CERTIFICATION

Casual certification over a user-id or user-attribute.

public static final int
CERTIFICATION_REVOCATION

The signature is used to revoke a user-id certification signature (DEFAULT_CERTIFICATION, NO_CERTIFICATION, CASUAL_CERTIFICATION, POSITIVE_CERTIFICATION) or DIRECT_KEY signature.

public static final int
DEFAULT_CERTIFICATION

Generic certification over a user-id or user-attribute.

public static final int
DIRECT_KEY

The signature is made directly over a primary key.

public static final int
KEY_REVOCATION

The signature is used to revoke a primary key (and in turn the whole certificate with all its subkeys).

public static final int
NO_CERTIFICATION

Persona certification over a user-id or user-attribute.

public static final int
POSITIVE_CERTIFICATION

Positive certification over a user-id or user-attribute.

public static final int
PRIMARYKEY_BINDING

Primary-Key Binding Signature to bind a signing-capable subkey to a primary key.

private final SignaturePacket
public static final int
STAND_ALONE

The signature is made only over its own signature subpackets.

public static final int
SUBKEY_BINDING

Subkey Binding Signature to bind a subkey to a primary key.

public static final int
SUBKEY_REVOCATION

The signature is used to revoke the binding of a particular subkey.

public static final int
THIRD_PARTY_CONFIRMATION

This signature is issued over another signature and can act as an attestation of that signature.

public static final int
TIMESTAMP

The signature is only meaningful for the timestamp contained in it.

private final TrustPacket
private volatile PGPContentVerifier
Inherited from org.bouncycastle.openpgp.PGPDefaultSignatureGenerator:
lastbsigOutsigTypeversion

Constructor Summary

AccessConstructor and Description
public
PGPSignature(BCPGInputStream
packet input stream
pIn
)

Parse a PGPSignature from an OpenPGP packet input stream.

pack-priv
pack-priv
pack-priv
PGPSignature(SignaturePacket sigPacket, TrustPacket trustPacket)

Method Summary

Modifier and TypeMethod and Description
private void
private static SignaturePacket
cast(Packet packet)

private void
private PGPSignatureSubpacketVector
pack-priv PGPContentVerifierBuilder
pack-priv boolean
pack-priv boolean
pack-priv boolean
pack-priv boolean
public void
encode(OutputStream
packet stream
outStream
)

Encode the signature to an OpenPGP packet stream.

public void
encode(OutputStream
stream to write the key encoding to.
outStream
,
boolean
if the purpose of encoding is to send key to other users.
forTransfer
)

Encode the signature to outStream, with trust packets stripped out if forTransfer is true.

private List<KeyIdentifier>
public Date

Returns:

the signature creation time.
getCreationTime
()

Return the creation time of the signature.

public byte[]

Returns:

digest prefix
getDigestPrefix
()

Return the digest prefix of the signature.

public byte[]

Returns:

OpenPGP packet encoding
getEncoded
()

Return the OpenPGP packet encoding of the signature.

public byte[]

Returns:

a encoded byte array representing the key.
getEncoded
(boolean
if the purpose of encoding is to send key to other users.
forTransfer
)

Return an encoding of the signature, with trust packets stripped out if forTransfer is true.

public int

Returns:

signature hash algorithm.
getHashAlgorithm
()

Return the hash algorithm associated with this signature.

public List<KeyIdentifier>

Returns:

hashed key identifiers
getHashedKeyIdentifiers
()

Return a list of all KeyIdentifiers that could be derived from any IssuerFingerprint or IssuerKeyID subpackets of the hashed signature subpacket area.

public PGPSignatureSubpacketVector

Returns:

hashed signature subpackets
getHashedSubPackets
()

Return the hashed subpackets of the signature.

public int

Returns:

signature key algorithm.
getKeyAlgorithm
()

Return the key algorithm associated with this signature.

public long

Returns:

keyID of the signatures corresponding key.
getKeyID
()

Return the id of the key that created the signature.

public List<KeyIdentifier>

Returns:

all detectable KeyIdentifiers
getKeyIdentifiers
()

Create a list of KeyIdentifier objects, for all IssuerFingerprint and IssuerKeyID signature subpackets found in either the hashed or unhashed areas of the signature.

pack-priv byte[]

Returns:

salt
getSalt
()

Return the salt of a v6 signature.

public byte[]

Returns:

cryptographic signature
getSignature
()

Return the cryptographic raw signature contained in the OpenPGP signature packet.

public byte[]
public int

Returns:

type id
getSignatureType
()

Return the type id of the signature.

public List<KeyIdentifier>

Returns:

unhashed key identifiers
getUnhashedKeyIdentifiers
()

Return a list of all KeyIdentifiers that could be derived from any IssuerFingerprint or IssuerKeyID subpackets of the unhashed signature subpacket area.

public PGPSignatureSubpacketVector

Returns:

unhashed signature subpackets
getUnhashedSubPackets
()

Return the unhashed subpackets of the signature.

public int

Returns:

signature version number.
getVersion
()

Return the OpenPGP version number for this signature.

public boolean

Returns:

true if either hashed or unhashed subpackets are present, false otherwise.
hasSubpackets
()

Return true if the signature has either hashed or unhashed subpackets.

public void
init(PGPContentVerifierBuilderProvider
provide the implementation for signature verification
verifierBuilderProvider
,
PGPPublicKey
issuer public key
pubKey
)

Initialize the signature for verification.

pack-priv void
public boolean

Returns:

true if this signature represents a certification, false otherwise.
isCertification
()

Return true if this signature represents a certification.

public static boolean

Returns:

true if signatureType is a certification, false otherwise.
isCertification
(int signatureType)

Return true if the passed in signature type represents a certification, false if the signature type is not.

public static boolean

Returns:

true if both signatures contain the same cryptographic signature
isSignatureEncodingEqual
(PGPSignature
first signature
sig1
,
PGPSignature
second signature
sig2
)

Return true, if the cryptographic signature encoding of the two signatures match.

public static PGPSignature

Returns:

merged signature
join
(PGPSignature
first signature
sig1
,
PGPSignature
second signature
sig2
)

Join two copies of the same signature.

private void
public boolean

Returns:

true if the signature is correct
verify
()

Finish the verification and return true if the signature is "correct".

public boolean

Returns:

true if the signature matches, false otherwise.
verifyCertification
(PGPUserAttributeSubpacketVector
user attributes the key was stored under
userAttributes
,
PGPPublicKey
the key to be verified.
key
)

Verify the signature as certifying the passed in public key as associated with the passed in user attributes.

public boolean

Returns:

true if the signature matches, false otherwise.
verifyCertification
(String
id the key was stored under
id
,
PGPPublicKey
the key to be verified.
key
)

Verify the signature as certifying the passed in public key as associated with the passed in id.

public boolean

Returns:

true if the signature matches, false otherwise.
verifyCertification
(byte[]
id the key was stored under in its raw byte form.
rawID
,
PGPPublicKey
the key to be verified.
key
)

Verify the signature as certifying the passed in public key as associated with the passed in rawID.

public boolean

Returns:

true if the certification is valid, false otherwise.
verifyCertification
(PGPPublicKey
the key we are verifying against.
masterKey
,
PGPPublicKey
the key we are verifying.
pubKey
)

Verify a certification for the passed in key against the passed in master key.

public boolean

Returns:

true if the certification is valid, false otherwise.
verifyCertification
(PGPPublicKey
the key we are checking.
pubKey
)

Verify a key certification, such as a revocation, for the passed in key.

Inherited from org.bouncycastle.openpgp.PGPDefaultSignatureGenerator:
blockUpdategetAttributesHashupdateupdateupdateupdateWithIdDataupdateWithPublicKey

Field Detail

BINARY_DOCUMENTback to summary
public static final int BINARY_DOCUMENT

The signature is made over some binary data. No preprocessing is applied.
This signature type is used to create data signatures.

See Also
RFC9580 - Binary Signature of a Document
CANONICAL_TEXT_DOCUMENTback to summary
public static final int CANONICAL_TEXT_DOCUMENT

The signature is made over text data. In a preprocessing step, the text data is canonicalized (line endings may be altered).
This signature type is used to create data signatures.

See Also
RFC9580 - Text Signature of a Canonical Document
CASUAL_CERTIFICATIONback to summary
public static final int CASUAL_CERTIFICATION

Casual certification over a user-id or user-attribute. The issuer of a casual certification did some casual verification to check the authenticity of the identity claim.
This signature type is used to bind user information to primary keys, or to certify the identity claim of a third party.

See Also
RFC9580 - Casual Certification of a User ID an Public Key Packet
CERTIFICATION_REVOCATIONback to summary
public static final int CERTIFICATION_REVOCATION

The signature is used to revoke a user-id certification signature (DEFAULT_CERTIFICATION, NO_CERTIFICATION, CASUAL_CERTIFICATION, POSITIVE_CERTIFICATION) or DIRECT_KEY signature. Issued as a self-signature, it can be used to revoke an identity claim. Issued over a third-party certificate, it revokes the attestation of the third-party's claim.

See Also
RFC9580 - Certification Revocation Signature
DEFAULT_CERTIFICATIONback to summary
public static final int DEFAULT_CERTIFICATION

Generic certification over a user-id or user-attribute. The issuer of a generic certification does not make any claims as to what extent they checked the authenticity of the identity claim.
This signature type is used to bind user information to primary keys, or to certify the identity claim of a third party.

See Also
RFC9580 - Generic Certification Signature of a User ID and Public Key Packet
DIRECT_KEYback to summary
public static final int DIRECT_KEY

The signature is made directly over a primary key. If issued as a self-signature, its contents apply to the whole certificate, meaning this signature is appropriate to set algorithm preferences which also apply to its subkeys. Issued as a signature over a third-party certificate, it can be used to mark said certificate as a CA.

See Also
RFC9580 - Direct Key Signature
KEY_REVOCATIONback to summary
public static final int KEY_REVOCATION

The signature is used to revoke a primary key (and in turn the whole certificate with all its subkeys).

See Also
RFC9580 - Key Revocation Signature
NO_CERTIFICATIONback to summary
public static final int NO_CERTIFICATION

Persona certification over a user-id or user-attribute. The issuer of a persona certification did explicitly not check the authenticity of the identity claim.
This signature type is used to bind user information to primary keys, or to certify the identity claim of a third party.

See Also
RFC9580 - Persona Certification Signature of a User ID and Public Key Packet
POSITIVE_CERTIFICATIONback to summary
public static final int POSITIVE_CERTIFICATION

Positive certification over a user-id or user-attribute. The issuer of a positive certification did extensive effort to check the authenticity of the identity claim.
This signature type is used to bind user information to primary keys, or to certify the identity claim of a third party.

See Also
RFC9580 - Positive Certification Signature of a User ID and Public Key Packet
PRIMARYKEY_BINDINGback to summary
public static final int PRIMARYKEY_BINDING

Primary-Key Binding Signature to bind a signing-capable subkey to a primary key. This (back-) signature is used as an embedded signature in a SUBKEY_BINDING signature and acts as a claim by the subkey, stating that it is in fact a subkey of the primary key.

See Also
RFC9580 - Primary Key Binding Signature
sigPckback to summary
private final SignaturePacket sigPck
STAND_ALONEback to summary
public static final int STAND_ALONE

The signature is made only over its own signature subpackets.

See Also
RFC9580 - Standalone Signature
SUBKEY_BINDINGback to summary
public static final int SUBKEY_BINDING

Subkey Binding Signature to bind a subkey to a primary key. This signature type is used to bind a subkey to the primary key of a certificate.

See Also
RFC9580 - Subkey Binding Signature
SUBKEY_REVOCATIONback to summary
public static final int SUBKEY_REVOCATION

The signature is used to revoke the binding of a particular subkey.

See Also
RFC9580 - Subkey Revocation Signature
THIRD_PARTY_CONFIRMATIONback to summary
public static final int THIRD_PARTY_CONFIRMATION

This signature is issued over another signature and can act as an attestation of that signature. This concept can be used to "approve" third-party certifications over the own key, allowing third-party certifications to be published on key-servers that usually strip such signatures to prevent certificate flooding.

See Also
RFC9580 - Third-Party Confirmation Signature
TIMESTAMPback to summary
public static final int TIMESTAMP

The signature is only meaningful for the timestamp contained in it.

See Also
RFC9580 - Timestamp Signature
trustPckback to summary
private final TrustPacket trustPck
verifierback to summary
private volatile PGPContentVerifier verifier

Constructor Detail

PGPSignatureback to summary
public PGPSignature(BCPGInputStream pIn) throws IOException, PGPException

Parse a PGPSignature from an OpenPGP packet input stream.

Parameters
pIn:BCPGInputStream

packet input stream

PGPSignatureback to summary
pack-priv PGPSignature(PGPSignature signature)
PGPSignatureback to summary
pack-priv PGPSignature(SignaturePacket sigPacket)
PGPSignatureback to summary
pack-priv PGPSignature(SignaturePacket sigPacket, TrustPacket trustPacket)

Method Detail

addTrailerback to summary
private void addTrailer()
castback to summary
private static SignaturePacket cast(Packet packet) throws IOException
checkSaltSizeback to summary
private void checkSaltSize() throws PGPException
createSubpacketVectorback to summary
private PGPSignatureSubpacketVector createSubpacketVector(SignatureSubpacket[] pcks)
createVerifierProviderback to summary
pack-priv PGPContentVerifierBuilder createVerifierProvider(PGPContentVerifierBuilderProvider verifierBuilderProvider) throws PGPException
doVerifyCertificationback to summary
pack-priv boolean doVerifyCertification(PGPUserAttributeSubpacketVector userAttributes, PGPPublicKey key) throws PGPException
doVerifyCertificationback to summary
pack-priv boolean doVerifyCertification(byte[] rawID, PGPPublicKey key) throws PGPException
doVerifyCertificationback to summary
pack-priv boolean doVerifyCertification(PGPPublicKey masterKey, PGPPublicKey pubKey) throws PGPException
doVerifyCertificationback to summary
pack-priv boolean doVerifyCertification(PGPPublicKey pubKey) throws PGPException
encodeback to summary
public void encode(OutputStream outStream) throws IOException

Encode the signature to an OpenPGP packet stream. This method does not strip out any trust packets.

Parameters
outStream:OutputStream

packet stream

encodeback to summary
public void encode(OutputStream outStream, boolean forTransfer) throws IOException

Encode the signature to outStream, with trust packets stripped out if forTransfer is true.

Parameters
outStream:OutputStream

stream to write the key encoding to.

forTransfer:boolean

if the purpose of encoding is to send key to other users.

Exceptions
IOException:
in case of encoding error.
extractKeyIdentifiersback to summary
private List<KeyIdentifier> extractKeyIdentifiers(SignatureSubpacket[] subpackets)
getCreationTimeback to summary
public Date getCreationTime()

Return the creation time of the signature.

Returns:Date

the signature creation time.

getDigestPrefixback to summary
public byte[] getDigestPrefix()

Return the digest prefix of the signature.

Returns:byte[]

digest prefix

getEncodedback to summary
public byte[] getEncoded() throws IOException

Return the OpenPGP packet encoding of the signature.

Returns:byte[]

OpenPGP packet encoding

getEncodedback to summary
public byte[] getEncoded(boolean forTransfer) throws IOException

Return an encoding of the signature, with trust packets stripped out if forTransfer is true.

Parameters
forTransfer:boolean

if the purpose of encoding is to send key to other users.

Returns:byte[]

a encoded byte array representing the key.

Exceptions
IOException:
in case of encoding error.
getHashAlgorithmback to summary
public int getHashAlgorithm()

Return the hash algorithm associated with this signature.

Returns:int

signature hash algorithm.

getHashedKeyIdentifiersback to summary
public List<KeyIdentifier> getHashedKeyIdentifiers()

Return a list of all KeyIdentifiers that could be derived from any IssuerFingerprint or IssuerKeyID subpackets of the hashed signature subpacket area.

Returns:List<KeyIdentifier>

hashed key identifiers

getHashedSubPacketsback to summary
public PGPSignatureSubpacketVector getHashedSubPackets()

Return the hashed subpackets of the signature. Hashed signature subpackets are covered by the signature.

Returns:PGPSignatureSubpacketVector

hashed signature subpackets

getKeyAlgorithmback to summary
public int getKeyAlgorithm()

Return the key algorithm associated with this signature.

Returns:int

signature key algorithm.

getKeyIDback to summary
public long getKeyID()

Return the id of the key that created the signature.

Note

Since signatures of version 4 or later encode the issuer information inside a signature subpacket (IssuerKeyID or IssuerFingerprint), there is not a single source of truth for the key-id. To match any suitable issuer keys, use getKeyIdentifiers() instead.

Returns:long

keyID of the signatures corresponding key.

getKeyIdentifiersback to summary
public List<KeyIdentifier> getKeyIdentifiers()

Create a list of KeyIdentifier objects, for all IssuerFingerprint and IssuerKeyID signature subpackets found in either the hashed or unhashed areas of the signature.

Returns:List<KeyIdentifier>

all detectable KeyIdentifiers

getSaltback to summary
pack-priv byte[] getSalt()

Return the salt of a v6 signature.

Returns:byte[]

salt

getSignatureback to summary
public byte[] getSignature() throws PGPException

Return the cryptographic raw signature contained in the OpenPGP signature packet. The value is dependent on the signing algorithm.

Returns:byte[]

cryptographic signature

getSignatureTrailerback to summary
public byte[] getSignatureTrailer()
getSignatureTypeback to summary
public int getSignatureType()

Return the type id of the signature.

Returns:int

type id

See Also
RFC9580 - Signature Types
getUnhashedKeyIdentifiersback to summary
public List<KeyIdentifier> getUnhashedKeyIdentifiers()

Return a list of all KeyIdentifiers that could be derived from any IssuerFingerprint or IssuerKeyID subpackets of the unhashed signature subpacket area.

Returns:List<KeyIdentifier>

unhashed key identifiers

getUnhashedSubPacketsback to summary
public PGPSignatureSubpacketVector getUnhashedSubPackets()

Return the unhashed subpackets of the signature. As unhashed signature subpackets are NOT covered by the signature, an attacker might inject false information after the fact, therefore only "self-authenticating" information from this area can be trusted. Self-authenticating information are for example the org.bouncycastle.bcpg.sig.IssuerKeyID or org.bouncycastle.bcpg.sig.IssuerFingerprint, whose authenticity can be confirmed by verifying the signature using the declared key.

Returns:PGPSignatureSubpacketVector

unhashed signature subpackets

getVersionback to summary
public int getVersion()

Return the OpenPGP version number for this signature.

Returns:int

signature version number.

hasSubpacketsback to summary
public boolean hasSubpackets()

Return true if the signature has either hashed or unhashed subpackets.

Returns:boolean

true if either hashed or unhashed subpackets are present, false otherwise.

initback to summary
public void init(PGPContentVerifierBuilderProvider verifierBuilderProvider, PGPPublicKey pubKey) throws PGPException

Initialize the signature for verification.

Parameters
verifierBuilderProvider:PGPContentVerifierBuilderProvider

provide the implementation for signature verification

pubKey:PGPPublicKey

issuer public key

initback to summary
pack-priv void init(PGPContentVerifier verifier) throws PGPException
isCertificationback to summary
public boolean isCertification()

Return true if this signature represents a certification.

Returns:boolean

true if this signature represents a certification, false otherwise.

isCertificationback to summary
public static boolean isCertification(int signatureType)

Return true if the passed in signature type represents a certification, false if the signature type is not.

Returns:boolean

true if signatureType is a certification, false otherwise.

isSignatureEncodingEqualback to summary
public static boolean isSignatureEncodingEqual(PGPSignature sig1, PGPSignature sig2)

Return true, if the cryptographic signature encoding of the two signatures match.

Parameters
sig1:PGPSignature

first signature

sig2:PGPSignature

second signature

Returns:boolean

true if both signatures contain the same cryptographic signature

joinback to summary
public static PGPSignature join(PGPSignature sig1, PGPSignature sig2) throws PGPException

Join two copies of the same signature. As an entity might append additional information to an existing signatures unhashed subpacket area (e.g. an embedded THIRD_PARTY_CONFIRMATION signature), an implementation might want to join an existing instance of a signature with an updated copy, e.g. retrieved from a key server. This method merges both signature instances by joining unhashed subpackets.

Parameters
sig1:PGPSignature

first signature

sig2:PGPSignature

second signature

Returns:PGPSignature

merged signature

updateWithSaltback to summary
private void updateWithSalt() throws PGPException
verifyback to summary
public boolean verify() throws PGPException

Finish the verification and return true if the signature is "correct".

Note

The fact that this method returned

true
does not yet mean that the signature is valid. A correct signature may very well be expired, the issuer key may be revoked, etc. All these constraints are not checked by this method.
Returns:boolean

true if the signature is correct

verifyCertificationback to summary
public boolean verifyCertification(PGPUserAttributeSubpacketVector userAttributes, PGPPublicKey key) throws PGPException

Verify the signature as certifying the passed in public key as associated with the passed in user attributes.

Parameters
userAttributes:PGPUserAttributeSubpacketVector

user attributes the key was stored under

key:PGPPublicKey

the key to be verified.

Returns:boolean

true if the signature matches, false otherwise.

verifyCertificationback to summary
public boolean verifyCertification(String id, PGPPublicKey key) throws PGPException

Verify the signature as certifying the passed in public key as associated with the passed in id.

Parameters
id:String

id the key was stored under

key:PGPPublicKey

the key to be verified.

Returns:boolean

true if the signature matches, false otherwise.

verifyCertificationback to summary
public boolean verifyCertification(byte[] rawID, PGPPublicKey key) throws PGPException

Verify the signature as certifying the passed in public key as associated with the passed in rawID.

Parameters
rawID:byte[]

id the key was stored under in its raw byte form.

key:PGPPublicKey

the key to be verified.

Returns:boolean

true if the signature matches, false otherwise.

verifyCertificationback to summary
public boolean verifyCertification(PGPPublicKey masterKey, PGPPublicKey pubKey) throws PGPException

Verify a certification for the passed in key against the passed in master key.

Parameters
masterKey:PGPPublicKey

the key we are verifying against.

pubKey:PGPPublicKey

the key we are verifying.

Returns:boolean

true if the certification is valid, false otherwise.

verifyCertificationback to summary
public boolean verifyCertification(PGPPublicKey pubKey) throws PGPException

Verify a key certification, such as a revocation, for the passed in key.

Parameters
pubKey:PGPPublicKey

the key we are checking.

Returns:boolean

true if the certification is valid, false otherwise.