Class Identity


  • public class Identity
    extends java.lang.Object
    Identity instances are meant to contain data about a person, institution or service which is signed by a trusted authority. Identities can also be self-signed which does not provide any layer of trust if not used by a trusted authority. This means trusted authorities must obviously sign their identities by themselves. An Identity can be used to encrypt, decrypt and sign data The class is designed to be safely serializable so instances can easily be stored on disk. The private parts should be password encrypted.
    • Constructor Summary

      Constructors 
      Constructor Description
      Identity​(java.lang.String possessor, java.util.HashMap<java.lang.String,​java.lang.String> data, java.lang.String password)
      Creates an identity from the given data
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getHash()
      Hashes the information contained in the identity using SHA-256
      boolean isUnlocked()  
      boolean isValid​(java.security.PublicKey publicKey)
      Checks if the Signature of the identity is valid using a given public key.
      static Identity load​(java.nio.file.Path path)
      Loads an Identity from a file
      boolean save​(java.nio.file.Path path)
      Saves the Identity to file at a given path.
      Inexistent files will be created.
      java.lang.String toIndentedString()
      Like toString() but idents certain parts to make it better readable
      java.lang.String toString()
      Generates a String representation of this identity containing the data that is secure to be sent.
      boolean unlock​(java.lang.String password)
      Unlocks a loaded identity which makes it possible to use it
      • Methods inherited from class java.lang.Object

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

      • Identity

        public Identity​(java.lang.String possessor,
                        java.util.HashMap<java.lang.String,​java.lang.String> data,
                        java.lang.String password)
        Creates an identity from the given data
        Parameters:
        possessor - name of the person, institution or service that possesses the identity
        data - key-value pairs of data containing information about the possessor
        password - which should be used to encrypt the private parts
    • Method Detail

      • load

        public static Identity load​(java.nio.file.Path path)
        Loads an Identity from a file
        Parameters:
        path - of the identity file
        Returns:
        identity instance
      • save

        public boolean save​(java.nio.file.Path path)
        Saves the Identity to file at a given path.
        Inexistent files will be created. Existent files will be overridden.
        Parameters:
        path - of the file to save the Identity to
        Returns:
        true if the process was successful
      • unlock

        public boolean unlock​(java.lang.String password)
        Unlocks a loaded identity which makes it possible to use it
        Parameters:
        password - to unlock the identity with
        Returns:
        true if the unlocking process was successful, false otherwise
      • isValid

        public boolean isValid​(java.security.PublicKey publicKey)
        Checks if the Signature of the identity is valid using a given public key.
        Parameters:
        publicKey - to test the signature against
        Returns:
        true if the signature is valid, false otherwise
      • isUnlocked

        public boolean isUnlocked()
        Returns:
        true if the identity is unlocked and usable
      • getHash

        public java.lang.String getHash()
        Hashes the information contained in the identity using SHA-256
        Returns:
        the hashed information
      • toString

        public java.lang.String toString()
        Generates a String representation of this identity containing the data that is secure to be sent.
        Overrides:
        toString in class java.lang.Object
      • toIndentedString

        public java.lang.String toIndentedString()
        Like toString() but idents certain parts to make it better readable
        Returns:
        idented String representation