Class 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
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <A extends java.lang.Appendable>
      A
      append​(A sb)
      Outputs the generated random art
      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
      static <A extends java.lang.Appendable>
      A
      combine​(A sb, char separator, java.util.Collection<? extends KeyRandomArt> arts)
      Combines the arts in a user-friendly way so they are aligned with each other
      static java.lang.String combine​(SessionContext session, char separator, KeyIdentityProvider provider)
      Creates the combined representation of the random art entries for the provided keys
      static <A extends java.lang.Appendable>
      A
      combine​(SessionContext session, A sb, char separator, KeyIdentityProvider provider)
      Appends the combined random art entries for the provided keys
      static java.util.Collection<KeyRandomArt> generate​(SessionContext session, KeyIdentityProvider provider)
      Extracts and generates random art entries for all key in the provider
      java.lang.String getAlgorithm()  
      int getKeySize()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • 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 algorithm
        keySize - The key size in bits
        digest - The key digest
    • Method Detail

      • getAlgorithm

        public java.lang.String getAlgorithm()
        Specified by:
        getAlgorithm in interface AlgorithmNameProvider
        Returns:
        The algorithm that was used to generate the key - e.g., "RSA", "DSA", "EC".
      • getKeySize

        public int getKeySize()
        Specified by:
        getKeySize in interface KeySizeIndicator
        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 - The Appendable 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 class java.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 done
        arts - The KeyRandomArts to combine - ignored if null/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 - The SessionContext for invoking this load command - may be null 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 done
        provider - The KeyIdentityProvider - ignored if null 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 - The Appendable output writer
        Parameters:
        session - The SessionContext for invoking this load command - may be null if not invoked within a session context (e.g., offline tool or session unknown).
        sb - The writer
        separator - The separator to use between the arts - if empty char ('\0') then no separation is done
        provider - The KeyIdentityProvider - ignored if null 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)
      • 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 - The Appendable output writer
        Parameters:
        sb - The writer
        separator - The separator to use between the arts - if empty char ('\0') then no separation is done
        arts - The KeyRandomArts to combine - ignored if null/empty
        Returns:
        The updated writer instance
        Throws:
        java.io.IOException - If failed to write the combined result