Class KeyRandomArt
- java.lang.Object
-
- org.apache.sshd.common.config.keys.KeyRandomArt
-
- All Implemented Interfaces:
AlgorithmNameProvider
,KeySizeIndicator
public class KeyRandomArt extends java.lang.Object implements AlgorithmNameProvider, KeySizeIndicator
Draw an ASCII-Art representing the fingerprint so human brain can profit from its built-in pattern recognition ability. This technique is called "random art" and can be found in some scientific publications like this original paper: "Hash Visualization: a New Technique to improve Real-World Security", Perrig A. and Song D., 1999, International Workshop on Cryptographic Techniques and E-Commerce (CrypTEC '99)- See Also:
- Original article, C implementation
-
-
Constructor Summary
Constructors Constructor Description KeyRandomArt(java.lang.String algorithm, int keySize, byte[] digest)
KeyRandomArt(java.security.PublicKey key)
KeyRandomArt(java.security.PublicKey key, Digest d)
KeyRandomArt(java.security.PublicKey key, Factory<? extends Digest> f)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <A extends java.lang.Appendable>
Aappend(A sb)
Outputs the generated random artstatic java.lang.String
combine(char separator, java.util.Collection<? extends KeyRandomArt> arts)
Combines the arts in a user-friendly way so they are aligned with each otherstatic <A extends java.lang.Appendable>
Acombine(A sb, char separator, java.util.Collection<? extends KeyRandomArt> arts)
Combines the arts in a user-friendly way so they are aligned with each otherstatic java.lang.String
combine(SessionContext session, char separator, KeyIdentityProvider provider)
Creates the combined representation of the random art entries for the provided keysstatic <A extends java.lang.Appendable>
Acombine(SessionContext session, A sb, char separator, KeyIdentityProvider provider)
Appends the combined random art entries for the provided keysstatic java.util.Collection<KeyRandomArt>
generate(SessionContext session, KeyIdentityProvider provider)
Extracts and generates random art entries for all key in the providerjava.lang.String
getAlgorithm()
int
getKeySize()
java.lang.String
toString()
-
-
-
Field Detail
-
FLDBASE
public static final int FLDBASE
- See Also:
- Constant Field Values
-
FLDSIZE_Y
public static final int FLDSIZE_Y
- See Also:
- Constant Field Values
-
FLDSIZE_X
public static final int FLDSIZE_X
- See Also:
- Constant Field Values
-
AUGMENTATION_STRING
public static final java.lang.String AUGMENTATION_STRING
- See Also:
- Constant Field Values
-
algorithm
private final java.lang.String algorithm
-
keySize
private final int keySize
-
field
private final char[][] field
-
-
Constructor Detail
-
KeyRandomArt
public KeyRandomArt(java.security.PublicKey key) throws java.lang.Exception
- Throws:
java.lang.Exception
-
KeyRandomArt
public KeyRandomArt(java.security.PublicKey key, Factory<? extends Digest> f) throws java.lang.Exception
- Throws:
java.lang.Exception
-
KeyRandomArt
public KeyRandomArt(java.security.PublicKey key, Digest d) throws java.lang.Exception
- Throws:
java.lang.Exception
-
KeyRandomArt
public KeyRandomArt(java.lang.String algorithm, int keySize, byte[] digest)
- Parameters:
algorithm
- The key algorithmkeySize
- The key size in bitsdigest
- The key digest
-
-
Method Detail
-
getAlgorithm
public java.lang.String getAlgorithm()
- Specified by:
getAlgorithm
in interfaceAlgorithmNameProvider
- Returns:
- The algorithm that was used to generate the key - e.g., "RSA", "DSA", "EC".
-
getKeySize
public int getKeySize()
- Specified by:
getKeySize
in interfaceKeySizeIndicator
- Returns:
- The number of bits used in the key
-
append
public <A extends java.lang.Appendable> A append(A sb) throws java.io.IOException
Outputs the generated random art- Type Parameters:
A
- TheAppendable
output writer- Parameters:
sb
- The writer- Returns:
- The updated writer instance
- Throws:
java.io.IOException
- If failed to write the combined result
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
combine
public static java.lang.String combine(char separator, java.util.Collection<? extends KeyRandomArt> arts)
Combines the arts in a user-friendly way so they are aligned with each other- Parameters:
separator
- The separator to use between the arts - if empty char ('\0') then no separation is donearts
- TheKeyRandomArt
s to combine - ignored ifnull
/empty- Returns:
- The combined result
-
combine
public static java.lang.String combine(SessionContext session, char separator, KeyIdentityProvider provider) throws java.lang.Exception
Creates the combined representation of the random art entries for the provided keys- Parameters:
session
- TheSessionContext
for invoking this load command - may benull
if not invoked within a session context (e.g., offline tool or session unknown).separator
- The separator to use between the arts - if empty char ('\0') then no separation is doneprovider
- TheKeyIdentityProvider
- ignored ifnull
or has no keys to provide- Returns:
- The combined representation
- Throws:
java.lang.Exception
- If failed to extract or combine the entries- See Also:
combine(SessionContext, Appendable, char, KeyIdentityProvider)
-
combine
public static <A extends java.lang.Appendable> A combine(SessionContext session, A sb, char separator, KeyIdentityProvider provider) throws java.lang.Exception
Appends the combined random art entries for the provided keys- Type Parameters:
A
- TheAppendable
output writer- Parameters:
session
- TheSessionContext
for invoking this load command - may benull
if not invoked within a session context (e.g., offline tool or session unknown).sb
- The writerseparator
- The separator to use between the arts - if empty char ('\0') then no separation is doneprovider
- TheKeyIdentityProvider
- ignored ifnull
or has no keys to provide- Returns:
- The updated writer instance
- Throws:
java.lang.Exception
- If failed to extract or write the entries- See Also:
generate(SessionContext, KeyIdentityProvider)
,combine(Appendable, char, Collection)
-
generate
public static java.util.Collection<KeyRandomArt> generate(SessionContext session, KeyIdentityProvider provider) throws java.lang.Exception
Extracts and generates random art entries for all key in the provider- Parameters:
session
- TheSessionContext
for invoking this load command - may benull
if not invoked within a session context (e.g., offline tool or session unknown).provider
- TheKeyIdentityProvider
- ignored ifnull
or has no keys to provide- Returns:
- The extracted
KeyRandomArt
s - Throws:
java.lang.Exception
- If failed to extract the entries- See Also:
KeyIdentityProvider.loadKeys(SessionContext)
-
combine
public static <A extends java.lang.Appendable> A combine(A sb, char separator, java.util.Collection<? extends KeyRandomArt> arts) throws java.io.IOException
Combines the arts in a user-friendly way so they are aligned with each other- Type Parameters:
A
- TheAppendable
output writer- Parameters:
sb
- The writerseparator
- The separator to use between the arts - if empty char ('\0') then no separation is donearts
- TheKeyRandomArt
s to combine - ignored ifnull
/empty- Returns:
- The updated writer instance
- Throws:
java.io.IOException
- If failed to write the combined result
-
-