public class PublicKeyEntry extends Object implements Serializable
Represents a PublicKey
whose data is formatted according to
the OpenSSH format:
<key-type> <base64-encoded-public-key-data>
Modifier and Type | Field and Description |
---|---|
static char |
COMMENT_CHAR
Character used to denote a comment line in the keys file
|
static String |
STD_KEYFILE_FOLDER_NAME
Standard folder name used by OpenSSH to hold key files
|
Constructor and Description |
---|
PublicKeyEntry() |
PublicKeyEntry(String keyType,
byte... keyData) |
Modifier and Type | Method and Description |
---|---|
PublicKey |
appendPublicKey(Appendable sb,
PublicKeyEntryResolver fallbackResolver) |
static <A extends Appendable> |
appendPublicKeyEntry(A sb,
PublicKey key)
Encodes a public key data the same way as the
parsePublicKeyEntry(String) expects it |
boolean |
equals(Object obj) |
static Path |
getDefaultKeysFolderPath() |
byte[] |
getKeyData() |
String |
getKeyType() |
int |
hashCode() |
protected boolean |
isEquivalent(PublicKeyEntry e) |
static <E extends PublicKeyEntry> |
parsePublicKeyEntry(E entry,
String data) |
static PublicKeyEntry |
parsePublicKeyEntry(String data) |
PublicKey |
resolvePublicKey(PublicKeyEntryResolver fallbackResolver) |
void |
setKeyData(byte[] value) |
void |
setKeyType(String value) |
String |
toString() |
static String |
toString(PublicKey key) |
public static final char COMMENT_CHAR
public static final String STD_KEYFILE_FOLDER_NAME
public PublicKeyEntry()
public PublicKeyEntry(String keyType, byte... keyData)
public String getKeyType()
public void setKeyType(String value)
public byte[] getKeyData()
public void setKeyData(byte[] value)
public PublicKey resolvePublicKey(PublicKeyEntryResolver fallbackResolver) throws IOException, GeneralSecurityException
fallbackResolver
- The PublicKeyEntryResolver
to consult if
none of the built-in ones can be used. If null
and no built-in
resolver can be used then an InvalidKeySpecException
is thrown.PublicKey
- or null
if could not be
resolved. Note: may be called only after key type and data bytes
have been set or exception(s) may be thrownIOException
- If failed to decode the keyGeneralSecurityException
- If failed to generate the keypublic PublicKey appendPublicKey(Appendable sb, PublicKeyEntryResolver fallbackResolver) throws IOException, GeneralSecurityException
sb
- The Appendable
instance to encode the data intofallbackResolver
- The PublicKeyEntryResolver
to consult if
none of the built-in ones can be used. If null
and no built-in
resolver can be used then an InvalidKeySpecException
is thrown.PublicKey
or null
if could not resolve itIOException
- If failed to decode/encode the keyGeneralSecurityException
- If failed to generate the keyresolvePublicKey(PublicKeyEntryResolver)
protected boolean isEquivalent(PublicKeyEntry e)
public static final PublicKeyEntry parsePublicKeyEntry(String data) throws IllegalArgumentException
data
- Assumed to contain at least key-type base64-data
(anything
beyond the BASE64 data is ignored) - ignored if null
/emptyPublicKeyEntry
or null
if no dataIllegalArgumentException
- if bad format foundparsePublicKeyEntry(PublicKeyEntry, String)
public static final <E extends PublicKeyEntry> E parsePublicKeyEntry(E entry, String data) throws IllegalArgumentException
E
- The generic entry typeentry
- The PublicKeyEntry
whose contents are to be
updated - ignored if null
data
- Assumed to contain at least key-type base64-data
(anything
beyond the BASE64 data is ignored) - ignored if null
/emptyIllegalArgumentException
- if bad format foundpublic static String toString(PublicKey key) throws IllegalArgumentException
key
- The PublicKey
OpenSSH
encoded dataIllegalArgumentException
- If failed to encodeappendPublicKeyEntry(Appendable, PublicKey)
public static <A extends Appendable> A appendPublicKeyEntry(A sb, PublicKey key) throws IOException
parsePublicKeyEntry(String)
expects itA
- The generic appendable classsb
- The Appendable
instance to encode the data intokey
- The PublicKey
- ignored if null
IOException
- If failed to append the datapublic static Path getDefaultKeysFolderPath()
known_hosts
, authorized_keys
, etc.Copyright © 2008–2016 The Apache Software Foundation. All rights reserved.