Class Identity

java.lang.Object
dev.netcode.security.identity.Identity

public class Identity extends 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 Details

    • Identity

      public Identity(String possessor, HashMap<String,​String> data, 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 Details

    • load

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

      public boolean save(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(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
    • isValid

      public boolean isValid(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 String getHash()
      Hashes the information contained in the identity using SHA-256
      Returns:
      the hashed information
    • toString

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

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