Package org.pgpainless.key
Class OpenPgpFingerprint
- java.lang.Object
-
- org.pgpainless.key.OpenPgpFingerprint
-
- All Implemented Interfaces:
java.lang.CharSequence
,java.lang.Comparable<OpenPgpFingerprint>
- Direct Known Subclasses:
_64DigitFingerprint
,OpenPgpV4Fingerprint
public abstract class OpenPgpFingerprint extends java.lang.Object implements java.lang.CharSequence, java.lang.Comparable<OpenPgpFingerprint>
Abstract super class of different version OpenPGP fingerprints.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
fingerprint
protected static java.nio.charset.Charset
utf8
-
Constructor Summary
Constructors Constructor Description OpenPgpFingerprint(byte[] bytes)
OpenPgpFingerprint(java.lang.String fingerprint)
OpenPgpFingerprint(org.bouncycastle.openpgp.PGPKeyRing ring)
OpenPgpFingerprint(org.bouncycastle.openpgp.PGPPublicKey key)
OpenPgpFingerprint(org.bouncycastle.openpgp.PGPPublicKeyRing ring)
OpenPgpFingerprint(org.bouncycastle.openpgp.PGPSecretKeyRing ring)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description char
charAt(int i)
abstract long
getKeyId()
Return the key id of the OpenPGP public key thisOpenPgpFingerprint
belongs to.abstract int
getVersion()
Return the version of the fingerprint.protected abstract boolean
isValid(java.lang.String fp)
Check, whether the fingerprint consists of 40 valid hexadecimal characters.int
length()
static OpenPgpFingerprint
of(org.bouncycastle.openpgp.PGPKeyRing ring)
Return the fingerprint of the primary key of the given key ring.static OpenPgpFingerprint
of(org.bouncycastle.openpgp.PGPPublicKey key)
Return the fingerprint of the given key.static OpenPgpFingerprint
of(org.bouncycastle.openpgp.PGPSecretKey key)
Return the fingerprint of the given key.static OpenPgpFingerprint
parse(java.lang.String fingerprint)
Deprecated.Use the constructor methods of the versioned fingerprint subclasses instead.static OpenPgpFingerprint
parseFromBinary(byte[] binaryFingerprint)
Deprecated.use the parse() methods of the versioned fingerprint subclasses instead.abstract java.lang.String
prettyPrint()
Return a pretty printed representation of the fingerprint.java.lang.CharSequence
subSequence(int i, int i1)
java.lang.String
toString()
-
-
-
Constructor Detail
-
OpenPgpFingerprint
public OpenPgpFingerprint(java.lang.String fingerprint)
-
OpenPgpFingerprint
public OpenPgpFingerprint(@Nonnull byte[] bytes)
-
OpenPgpFingerprint
public OpenPgpFingerprint(org.bouncycastle.openpgp.PGPPublicKey key)
-
OpenPgpFingerprint
public OpenPgpFingerprint(@Nonnull org.bouncycastle.openpgp.PGPPublicKeyRing ring)
-
OpenPgpFingerprint
public OpenPgpFingerprint(@Nonnull org.bouncycastle.openpgp.PGPSecretKeyRing ring)
-
OpenPgpFingerprint
public OpenPgpFingerprint(@Nonnull org.bouncycastle.openpgp.PGPKeyRing ring)
-
-
Method Detail
-
of
public static OpenPgpFingerprint of(org.bouncycastle.openpgp.PGPSecretKey key)
Return the fingerprint of the given key. This method automatically matches key versions to fingerprint implementations.- Parameters:
key
- key- Returns:
- fingerprint
-
of
public static OpenPgpFingerprint of(org.bouncycastle.openpgp.PGPPublicKey key)
Return the fingerprint of the given key. This method automatically matches key versions to fingerprint implementations.- Parameters:
key
- key- Returns:
- fingerprint
-
of
public static OpenPgpFingerprint of(org.bouncycastle.openpgp.PGPKeyRing ring)
Return the fingerprint of the primary key of the given key ring. This method automatically matches key versions to fingerprint implementations.- Parameters:
ring
- key ring- Returns:
- fingerprint
-
parse
@Deprecated public static OpenPgpFingerprint parse(java.lang.String fingerprint)
Deprecated.Use the constructor methods of the versioned fingerprint subclasses instead.Try to parse anOpenPgpFingerprint
from the given fingerprint string. If the trimmed fingerprint without whitespace is 64 characters long, it is either a v5 or v6 fingerprint. In this case, we return a_64DigitFingerprint
. Since this is ambiguous, it is generally recommended to know the version of the key beforehand.- Parameters:
fingerprint
- fingerprint- Returns:
- parsed fingerprint
-
parseFromBinary
@Deprecated public static OpenPgpFingerprint parseFromBinary(byte[] binaryFingerprint)
Deprecated.use the parse() methods of the versioned fingerprint subclasses instead.Parse a binary OpenPGP fingerprint into anOpenPgpFingerprint
object.- Parameters:
binaryFingerprint
- binary representation of the fingerprint- Returns:
- parsed fingerprint
-
getVersion
public abstract int getVersion()
Return the version of the fingerprint.- Returns:
- version
-
isValid
protected abstract boolean isValid(@Nonnull java.lang.String fp)
Check, whether the fingerprint consists of 40 valid hexadecimal characters.- Parameters:
fp
- fingerprint to check.- Returns:
- true if fingerprint is valid.
-
getKeyId
public abstract long getKeyId()
Return the key id of the OpenPGP public key thisOpenPgpFingerprint
belongs to. This method can be implemented for V4 and V5 fingerprints. V3 key-IDs cannot be derived from the fingerprint, but we don't care, since V3 is deprecated.- Returns:
- key id
- See Also:
- RFC-4880 ยง12.2: Key IDs and Fingerprints
-
length
public int length()
- Specified by:
length
in interfacejava.lang.CharSequence
-
charAt
public char charAt(int i)
- Specified by:
charAt
in interfacejava.lang.CharSequence
-
subSequence
public java.lang.CharSequence subSequence(int i, int i1)
- Specified by:
subSequence
in interfacejava.lang.CharSequence
-
toString
@Nonnull public java.lang.String toString()
- Specified by:
toString
in interfacejava.lang.CharSequence
- Overrides:
toString
in classjava.lang.Object
-
prettyPrint
public abstract java.lang.String prettyPrint()
Return a pretty printed representation of the fingerprint.- Returns:
- pretty printed fingerprint
-
-