Top Description Fields Constructors Methods
org.bouncycastle.bcpg

public Class SignaturePacket

extends ContainedPacket
implements PublicKeyAlgorithmTags
Class Inheritance
All Implemented Interfaces
org.bouncycastle.bcpg.PublicKeyAlgorithmTags
Imports
java.io.ByteArrayInputStream, .ByteArrayOutputStream, .IOException, java.util.Vector, org.bouncycastle.bcpg.sig.IssuerFingerprint, .IssuerKeyID, .SignatureCreationTime, org.bouncycastle.util.Arrays, .Pack, org.bouncycastle.util.io.Streams

generic signature packet

Field Summary

Modifier and TypeField and Description
private long
private byte[]
private int
private SignatureSubpacket[]
private int
private long
private byte[]
private MPInteger[]
private byte[]
private int
private SignatureSubpacket[]
private int
public static final int
public static final int
public static final int
public static final int
public static final int

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv
SignaturePacket(BCPGInputStream in, boolean newPacketFormat)

public
SignaturePacket(int signatureType, long keyID, int keyAlgorithm, int hashAlgorithm, SignatureSubpacket[] hashedData, SignatureSubpacket[] unhashedData, byte[] fingerPrint, MPInteger[] signature)

Generate a version 4 signature packet.

public
SignaturePacket(int version, int signatureType, long keyID, int keyAlgorithm, int hashAlgorithm, long creationTime, byte[] fingerPrint, MPInteger[] signature)

Generate a version 2/3 signature packet.

public
SignaturePacket(int version, int signatureType, long keyID, int keyAlgorithm, int hashAlgorithm, SignatureSubpacket[] hashedData, SignatureSubpacket[] unhashedData, byte[] fingerPrint, MPInteger[] signature)

public
SignaturePacket(int version, int signatureType, long keyID, int keyAlgorithm, int hashAlgorithm, SignatureSubpacket[] hashedData, SignatureSubpacket[] unhashedData, byte[] fingerPrint, byte[] signatureEncoding, byte[] salt)

public
SignaturePacket(int version, int signatureType, long keyID, int keyAlgorithm, int hashAlgorithm, SignatureSubpacket[] hashedData, SignatureSubpacket[] unhashedData, byte[] fingerPrint, MPInteger[] signature, byte[] salt)

Method Summary

Modifier and TypeMethod and Description
public void
public static SignaturePacket
fromByteArray(byte[] data)

public long

Returns:

the creation time in millis
getCreationTime
()

Return the creation time of the signature in milli-seconds.

public byte[]

Returns:

fingerprint (digest prefix) of the signature
getFingerPrint
()

Return the signature's fingerprint.

public int
getHashAlgorithm()

return the hashAlgorithm tag

public SignatureSubpacket[]
public int
getKeyAlgorithm()

return the encryption algorithm tag

public long

Returns:

the keyID that created the signature.
getKeyID
()

return the keyID

public byte[]

Returns:

salt
getSalt
()

Return the signature's salt.

public MPInteger[]
getSignature()

return the signature as a set of integers - note this is normalised to be the ASN.1 encoding of what appears in the signature packet.

public byte[]

Returns:

uninterpreted signature bytes.
getSignatureBytes
()

Return the byte encoding of the signature section.

public byte[]

Returns:

byte[]
getSignatureTrailer
()

return the signature trailer that must be included with the data to reconstruct the signature

public int
getSignatureType()

return the signature type.

public SignatureSubpacket[]
public int
getVersion()

get the version number

private void
parseSignature(BCPGInputStream
input stream which skipped the head of the signature
in
)

Parse the algorithm-specific signature encoding.

private void
parseSubpackets(BCPGInputStream
input stream which skipped to after the hash algorithm octet
in
)

Parse the hashed and unhashed signature subpacket areas of the signature.

private void
parseV2_V3(BCPGInputStream
input stream which already skipped over the version number
in
)

Parse a version 2 or version 3 signature.

private void
parseV4_V5(BCPGInputStream
input stream which already skipped over the version number
in
)

Parse a version 4 or version 5 signature.

private void
parseV6(BCPGInputStream
input stream which already skipped over the version number
in
)

Parse a version 6 signature.

private Vector<SignatureSubpacket>
private void
private void
setIssuerKeyId()

Iterate over the hashed and unhashed signature subpackets to identify either a IssuerKeyID or IssuerFingerprint subpacket to derive the issuer key-ID from.

private void
Inherited from org.bouncycastle.bcpg.ContainedPacket:
getEncodedgetEncoded

Field Detail

creationTimeback to summary
private long creationTime
fingerPrintback to summary
private byte[] fingerPrint
hashAlgorithmback to summary
private int hashAlgorithm
hashedDataback to summary
private SignatureSubpacket[] hashedData
keyAlgorithmback to summary
private int keyAlgorithm
keyIDback to summary
private long keyID
saltback to summary
private byte[] salt
signatureback to summary
private MPInteger[] signature
signatureEncodingback to summary
private byte[] signatureEncoding
signatureTypeback to summary
private int signatureType
unhashedDataback to summary
private SignatureSubpacket[] unhashedData
versionback to summary
private int version
VERSION_2back to summary
public static final int VERSION_2
VERSION_3back to summary
public static final int VERSION_3
VERSION_4back to summary
public static final int VERSION_4
VERSION_5back to summary
public static final int VERSION_5
VERSION_6back to summary
public static final int VERSION_6

Constructor Detail

SignaturePacketback to summary
pack-priv SignaturePacket(BCPGInputStream in) throws IOException
SignaturePacketback to summary
pack-priv SignaturePacket(BCPGInputStream in, boolean newPacketFormat) throws IOException
SignaturePacketback to summary
public SignaturePacket(int signatureType, long keyID, int keyAlgorithm, int hashAlgorithm, SignatureSubpacket[] hashedData, SignatureSubpacket[] unhashedData, byte[] fingerPrint, MPInteger[] signature)

Generate a version 4 signature packet.

SignaturePacketback to summary
public SignaturePacket(int version, int signatureType, long keyID, int keyAlgorithm, int hashAlgorithm, long creationTime, byte[] fingerPrint, MPInteger[] signature)

Generate a version 2/3 signature packet.

SignaturePacketback to summary
public SignaturePacket(int version, int signatureType, long keyID, int keyAlgorithm, int hashAlgorithm, SignatureSubpacket[] hashedData, SignatureSubpacket[] unhashedData, byte[] fingerPrint, MPInteger[] signature)
SignaturePacketback to summary
public SignaturePacket(int version, int signatureType, long keyID, int keyAlgorithm, int hashAlgorithm, SignatureSubpacket[] hashedData, SignatureSubpacket[] unhashedData, byte[] fingerPrint, byte[] signatureEncoding, byte[] salt)
SignaturePacketback to summary
public SignaturePacket(int version, int signatureType, long keyID, int keyAlgorithm, int hashAlgorithm, SignatureSubpacket[] hashedData, SignatureSubpacket[] unhashedData, byte[] fingerPrint, MPInteger[] signature, byte[] salt)

Method Detail

encodeback to summary
public void encode(BCPGOutputStream out) throws IOException

Implements abstract org.bouncycastle.bcpg.ContainedPacket.encode.

fromByteArrayback to summary
public static SignaturePacket fromByteArray(byte[] data) throws IOException
getCreationTimeback to summary
public long getCreationTime()

Return the creation time of the signature in milli-seconds.

Returns:long

the creation time in millis

getFingerPrintback to summary
public byte[] getFingerPrint()

Return the signature's fingerprint.

Returns:byte[]

fingerprint (digest prefix) of the signature

getHashAlgorithmback to summary
public int getHashAlgorithm()

return the hashAlgorithm tag

getHashedSubPacketsback to summary
public SignatureSubpacket[] getHashedSubPackets()
getKeyAlgorithmback to summary
public int getKeyAlgorithm()

return the encryption algorithm tag

getKeyIDback to summary
public long getKeyID()

return the keyID

Returns:long

the keyID that created the signature.

getSaltback to summary
public byte[] getSalt()

Return the signature's salt. Only for v6 signatures.

Returns:byte[]

salt

getSignatureback to summary
public MPInteger[] getSignature()

return the signature as a set of integers - note this is normalised to be the ASN.1 encoding of what appears in the signature packet. Note, that Ed25519 and Ed448 returns null, as the raw signature is stored in signatureEncoding only. For those, use getSignatureBytes() instead.

getSignatureBytesback to summary
public byte[] getSignatureBytes()

Return the byte encoding of the signature section.

Returns:byte[]

uninterpreted signature bytes.

getSignatureTrailerback to summary
public byte[] getSignatureTrailer()

return the signature trailer that must be included with the data to reconstruct the signature

Returns:byte[]

byte[]

getSignatureTypeback to summary
public int getSignatureType()

return the signature type.

getUnhashedSubPacketsback to summary
public SignatureSubpacket[] getUnhashedSubPackets()
getVersionback to summary
public int getVersion()

get the version number

parseSignatureback to summary
private void parseSignature(BCPGInputStream in) throws IOException

Parse the algorithm-specific signature encoding. Ed25519 and Ed448 do not populate the signature MPInteger field, but instead read the raw signature to signatureEncoding directly.

Parameters
in:BCPGInputStream

input stream which skipped the head of the signature

Exceptions
IOException:
if the packet is malformed
parseSubpacketsback to summary
private void parseSubpackets(BCPGInputStream in) throws IOException

Parse the hashed and unhashed signature subpacket areas of the signature. Version 4 and 5 signature encode the area length using 2 octets, while version 6 uses 4 octet lengths instead.

Parameters
in:BCPGInputStream

input stream which skipped to after the hash algorithm octet

Exceptions
IOException:
if the packet is malformed
parseV2_V3back to summary
private void parseV2_V3(BCPGInputStream in) throws IOException

Parse a version 2 or version 3 signature.

Parameters
in:BCPGInputStream

input stream which already skipped over the version number

Exceptions
IOException:
if the packet is malformed
See Also
Version 3 packet format
parseV4_V5back to summary
private void parseV4_V5(BCPGInputStream in) throws IOException

Parse a version 4 or version 5 signature. The difference between version 4 and 5 is that a version 5 signature contains additional metadata.

Parameters
in:BCPGInputStream

input stream which already skipped over the version number

Exceptions
IOException:
if the packet is malformed
See Also
Version 4 packet format, Version 5 packet format
parseV6back to summary
private void parseV6(BCPGInputStream in) throws IOException

Parse a version 6 signature. Version 6 signatures do use 4 octet subpacket area length descriptors and contain an additional salt value (which may or may not be of size 0, LibrePGP and OpenPGP are in disagreement here).

Parameters
in:BCPGInputStream

input stream which already skipped over the version number

Exceptions
IOException:
if the packet is malformed
See Also
OpenPGP - Version 6 packet format
readSignatureSubpacketVectorback to summary
private Vector<SignatureSubpacket> readSignatureSubpacketVector(BCPGInputStream in) throws IOException
setCreationTimeback to summary
private void setCreationTime()
setIssuerKeyIdback to summary
private void setIssuerKeyId()

Iterate over the hashed and unhashed signature subpackets to identify either a IssuerKeyID or IssuerFingerprint subpacket to derive the issuer key-ID from. The issuer IssuerKeyID and IssuerFingerprint subpacket information is "self-authenticating", as its authenticity can be verified by checking the signature with the corresponding key. Therefore, we can also check the unhashed signature subpacket area.

writeSignatureSubpacketArrayback to summary
private void writeSignatureSubpacketArray(ByteArrayOutputStream sOut, BCPGOutputStream pOut, SignatureSubpacket[] array) throws IOException