Package org.bouncycastle.bcpg
Class KeyIdentifier
java.lang.Object
org.bouncycastle.bcpg.KeyIdentifier
Utility class for matching key-ids / fingerprints.
A
KeyIdentifier can be created from either a 64-bit key-id, a fingerprint, or both.
This class was created to enable a seamless transition from use of key-ids in the API
towards identifying keys via fingerprints.-
Constructor Summary
ConstructorsConstructorDescriptionKeyIdentifier(byte[] fingerprint) Create a newKeyIdentifierbased on a keys fingerprint.KeyIdentifier(byte[] fingerprint, long keyId) Create aKeyIdentifierbased on the given fingerprint and key-id.KeyIdentifier(long keyId) Create aKeyIdentifierbased on the given key-id.KeyIdentifier(String hexEncoded) -
Method Summary
Modifier and TypeMethodDescriptionbooleanbyte[]Return the fingerprint of theKeyIdentifier.longgetKeyId()Return the key-id of theKeyIdentifier.booleanhasFingerprint(byte[] fingerprint) Return true if the KeyIdentifier has a fingerprint corresponding to the passed in one.inthashCode()booleanisPresentIn(List<KeyIdentifier> others) Return true, if thisKeyIdentifieris present in the given list ofKeyIdentifier.booleanReturns true, if theKeyIdentifierspecifies a wildcard (matches anything).static booleanmatches(List<KeyIdentifier> identifiers, KeyIdentifier identifier, boolean explicit) booleanmatches(KeyIdentifier other) Return true, if thisKeyIdentifiermatches the given otherKeyIdentifier.toString()static KeyIdentifierwildcard()Create a wildcardKeyIdentifier.
-
Constructor Details
-
KeyIdentifier
-
KeyIdentifier
public KeyIdentifier(byte[] fingerprint) Create a newKeyIdentifierbased on a keys fingerprint. For fingerprints matching the format of a v4, v5 or v6 key, the constructor will try to derive the corresponding key-id from the fingerprint.- Parameters:
fingerprint- fingerprint
-
KeyIdentifier
public KeyIdentifier(byte[] fingerprint, long keyId) Create aKeyIdentifierbased on the given fingerprint and key-id.- Parameters:
fingerprint- fingerprintkeyId- key-id
-
KeyIdentifier
public KeyIdentifier(long keyId) - Parameters:
keyId- key-id
-
-
Method Details
-
wildcard
Create a wildcardKeyIdentifier.- Returns:
- wildcard key identifier
-
getFingerprint
public byte[] getFingerprint()Return the fingerprint of theKeyIdentifier.fingerprintmight be null, if theKeyIdentifierwas created from just a key-id. IfisWildcard()returns true, this method returns an empty, but non-null array.- Returns:
- fingerprint
-
getKeyId
public long getKeyId()Return the key-id of theKeyIdentifier. This might be0LifisWildcard()returns true, or if an unknown fingerprint was passed in.- Returns:
- key-id
-
isWildcard
public boolean isWildcard()Returns true, if theKeyIdentifierspecifies a wildcard (matches anything). This is for example used with anonymous recipient key-ids / fingerprints, where the recipient needs to try all available keys to decrypt the message.- Returns:
- is wildcard
-
hasFingerprint
public boolean hasFingerprint(byte[] fingerprint) Return true if the KeyIdentifier has a fingerprint corresponding to the passed in one.- Parameters:
fingerprint- the fingerprint to match against.- Returns:
- true if there's a match, false otherwise.
-
matches
Return true, if thisKeyIdentifiermatches the given otherKeyIdentifier. This will return true if the fingerprint matches, or if the key-id matches, or ifisWildcard()returns true.- Parameters:
other- the identifier we are matching against.- Returns:
- true if we match other, false otherwise.
-
matches
public static boolean matches(List<KeyIdentifier> identifiers, KeyIdentifier identifier, boolean explicit) -
isPresentIn
Return true, if thisKeyIdentifieris present in the given list ofKeyIdentifier. This will return true if a fingerprint matches, or if a key-id matches, or ifisWildcard()returns true.- Parameters:
others- the list of key identifiers to check.- Returns:
- true, if the identifier is present in the list, false otherwise.
-
equals
-
hashCode
public int hashCode() -
toString
-