- java.lang.Object
-
- dev.netcode.security.identity.Identity
-
public class Identity extends java.lang.ObjectIdentity 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.StringgetHash()Hashes the information contained in the identity using SHA-256booleanisUnlocked()booleanisValid(java.security.PublicKey publicKey)Checks if theSignatureof the identity is valid using a given public key.static Identityload(java.nio.file.Path path)Loads an Identity from a filebooleansave(java.nio.file.Path path)Saves the Identity to file at a given path.
Inexistent files will be created.java.lang.StringtoIndentedString()LiketoString()but idents certain parts to make it better readablejava.lang.StringtoString()Generates a String representation of this identity containing the data that is secure to be sent.booleanunlock(java.lang.String password)Unlocks a loaded identity which makes it possible to use it
-
-
-
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 identitydata- key-value pairs of data containing information about the possessorpassword- 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 theSignatureof 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:
toStringin classjava.lang.Object
-
toIndentedString
public java.lang.String toIndentedString()
LiketoString()but idents certain parts to make it better readable- Returns:
- idented String representation
-
-