public class PublicKeyEntry
extends java.lang.Object
implements java.io.Serializable
Represents a PublicKey
whose data is formatted according to
the OpenSSH format:
<key-type> <base64-encoded-public-key-data>
Modifier and Type | Class and Description |
---|---|
private static class |
PublicKeyEntry.LazyDefaultKeysFolderHolder |
Modifier and Type | Field and Description |
---|---|
static char |
COMMENT_CHAR
Character used to denote a comment line in the keys file
|
private byte[] |
keyData |
private java.lang.String |
keyType |
private static long |
serialVersionUID |
static java.lang.String |
STD_KEYFILE_FOLDER_NAME
Standard folder name used by OpenSSH to hold key files
|
Constructor and Description |
---|
PublicKeyEntry() |
PublicKeyEntry(java.lang.String keyType,
byte... keyData) |
Modifier and Type | Method and Description |
---|---|
java.security.PublicKey |
appendPublicKey(java.lang.Appendable sb,
PublicKeyEntryResolver fallbackResolver) |
static <A extends java.lang.Appendable> |
appendPublicKeyEntry(A sb,
java.security.PublicKey key)
Encodes a public key data the same way as the
parsePublicKeyEntry(String) expects it |
boolean |
equals(java.lang.Object obj) |
static java.nio.file.Path |
getDefaultKeysFolderPath() |
byte[] |
getKeyData() |
java.lang.String |
getKeyType() |
int |
hashCode() |
protected boolean |
isEquivalent(PublicKeyEntry e) |
static <E extends PublicKeyEntry> |
parsePublicKeyEntry(E entry,
java.lang.String encData) |
static PublicKeyEntry |
parsePublicKeyEntry(java.lang.String encData) |
java.security.PublicKey |
resolvePublicKey(PublicKeyEntryResolver fallbackResolver) |
void |
setKeyData(byte[] value) |
void |
setKeyType(java.lang.String value) |
java.lang.String |
toString() |
static java.lang.String |
toString(java.security.PublicKey key) |
public static final char COMMENT_CHAR
public static final java.lang.String STD_KEYFILE_FOLDER_NAME
private static final long serialVersionUID
private java.lang.String keyType
private byte[] keyData
public PublicKeyEntry()
public PublicKeyEntry(java.lang.String keyType, byte... keyData)
public java.lang.String getKeyType()
public void setKeyType(java.lang.String value)
public byte[] getKeyData()
public void setKeyData(byte[] value)
public java.security.PublicKey resolvePublicKey(PublicKeyEntryResolver fallbackResolver) throws java.io.IOException, java.security.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 thrownjava.io.IOException
- If failed to decode the keyjava.security.GeneralSecurityException
- If failed to generate the keypublic java.security.PublicKey appendPublicKey(java.lang.Appendable sb, PublicKeyEntryResolver fallbackResolver) throws java.io.IOException, java.security.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 itjava.io.IOException
- If failed to decode/encode the keyjava.security.GeneralSecurityException
- If failed to generate the keyresolvePublicKey(PublicKeyEntryResolver)
public int hashCode()
hashCode
in class java.lang.Object
protected boolean isEquivalent(PublicKeyEntry e)
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public static PublicKeyEntry parsePublicKeyEntry(java.lang.String encData) throws java.lang.IllegalArgumentException
encData
- Assumed to contain at least key-type base64-data
(anything beyond the BASE64 data is ignored) - ignored if null
/emptyPublicKeyEntry
or null
if no datajava.lang.IllegalArgumentException
- if bad format foundparsePublicKeyEntry(PublicKeyEntry, String)
public static <E extends PublicKeyEntry> E parsePublicKeyEntry(E entry, java.lang.String encData) throws java.lang.IllegalArgumentException
E
- The generic entry typeentry
- The PublicKeyEntry
whose contents are to be
updated - ignored if null
encData
- Assumed to contain at least key-type base64-data
(anything
beyond the BASE64 data is ignored) - ignored if null
/emptyjava.lang.IllegalArgumentException
- if bad format foundpublic static java.lang.String toString(java.security.PublicKey key) throws java.lang.IllegalArgumentException
key
- The PublicKey
OpenSSH
encoded datajava.lang.IllegalArgumentException
- If failed to encodeappendPublicKeyEntry(Appendable, PublicKey)
public static <A extends java.lang.Appendable> A appendPublicKeyEntry(A sb, java.security.PublicKey key) throws java.io.IOException
parsePublicKeyEntry(String)
expects itA
- The generic appendable classsb
- The Appendable
instance to encode the data intokey
- The PublicKey
- ignored if null
java.io.IOException
- If failed to append the datapublic static java.nio.file.Path getDefaultKeysFolderPath()
known_hosts
, authorized_keys
, etc.