Package org.trustdeck.algorithms
Class Pseudonymizer
java.lang.Object
org.trustdeck.algorithms.Pseudonymizer
- Direct Known Subclasses:
BLAKE3Pseudonymizer,ConsecutivePseudonymizer,MD5Pseudonymizer,RandomAlphabetPseudonymizer,RandomNumberPseudonymizer,SHA1Pseudonymizer,SHA2Pseudonymizer,SHA3Pseudonymizer,XxHashPseudonymizer
An abstract class for different pseudonymization algorithms
- Author:
- Armin Müller
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDetermines the default number of retries when a generated random number is already in use.static final charThe default character used for the padding of the generated pseudonyms.static final intThe standard length for the generated pseudonyms.static final StringString to determine that a domain reaches its filling point at which new pseudonyms are not reasonably probable generated anymore.static final StringString to determine that a pseudonymization process failed. -
Constructor Summary
ConstructorsConstructorDescriptionBasic constructor.Pseudonymizer(boolean paddingWanted, int pseudonymValueLength, char paddingChar, String domainName) A constructor that allows to set whether or not the created pseudonyms should be padded as well as the desired pseudonym value length and the character used for padding.Pseudonymizer(boolean paddingWanted, Algorithm algorithm) A constructor that allows to set whether or not the created pseudonyms should be padded.Pseudonymizer(boolean paddingWanted, Domain domain) A constructor that allows to set whether or not the created pseudonyms should be padded.Pseudonymizer(String domainName) Basic constructor. -
Method Summary
Modifier and TypeMethodDescriptionaddCheckDigit(String pseudonym, boolean addInsteadOfLastChar, String domainName, String domainPrefix) Method to add a check digit (or check character) to a pseudonym.addPadding(String pseudonym, int lengthAfterPadding, char paddingChar) A method to add padding to a given pseudonym.correctPseudonymLength(String pseudonym) Corrects the length of the generated pseudonym.booleanpersist()Method to persist the consecutive value in the database.abstract Stringpseudonymize(String identifier, String domainPrefix) Abstract method for the pseudonymization of an identifier.
-
Field Details
-
DEFAULT_VALUE_LENGTH
public static final int DEFAULT_VALUE_LENGTHThe standard length for the generated pseudonyms.- See Also:
-
DEFAULT_PADDING_CHAR
public static final char DEFAULT_PADDING_CHARThe default character used for the padding of the generated pseudonyms.- See Also:
-
DEFAULT_NUMBER_OF_RETRIES
public static final int DEFAULT_NUMBER_OF_RETRIESDetermines the default number of retries when a generated random number is already in use.- See Also:
-
DOMAIN_FULL
String to determine that a domain reaches its filling point at which new pseudonyms are not reasonably probable generated anymore.- See Also:
-
PSEUDONYMIZATION_FAILED
String to determine that a pseudonymization process failed.- See Also:
-
-
Constructor Details
-
Pseudonymizer
public Pseudonymizer()Basic constructor. Initializes the values used for pseudonymization. Padding is turned off. (The pseudonym value length is automatically set to the default, as well as the padding character.) -
Pseudonymizer
Basic constructor. Initializes the values used for pseudonymization. Padding is turned off. (The pseudonym value length is automatically set to the default, as well as the padding character.)- Parameters:
domainName- the name of the domain to which the record belongs to
-
Pseudonymizer
public Pseudonymizer(boolean paddingWanted, int pseudonymValueLength, char paddingChar, String domainName) A constructor that allows to set whether or not the created pseudonyms should be padded as well as the desired pseudonym value length and the character used for padding.- Parameters:
paddingWanted- whether or not the pseudonyms should be padded to a certain lengthpseudonymValueLength- the desired length of the pseudonym valuepaddingChar- the character that should be used for paddingdomainName- the name of the domain to which the record belongs to
-
Pseudonymizer
A constructor that allows to set whether or not the created pseudonyms should be padded. All other information will be directly retrieved from the provided domain object.- Parameters:
paddingWanted- whether or not the pseudonyms should be padded to a certain lengthdomain- the domain object containing the necessary configuration information
-
Pseudonymizer
A constructor that allows to set whether or not the created pseudonyms should be padded. All other information will be directly retrieved from the provided domain object.- Parameters:
paddingWanted- whether or not the pseudonyms should be padded to a certain lengthalgorithm- the algorithm object containing the necessary configuration information
-
-
Method Details
-
pseudonymize
Abstract method for the pseudonymization of an identifier.- Parameters:
identifier- the value to be pseudonymizeddomainPrefix- the prefix for the domain- Returns:
- a pseudonym in the form of domainPrefix-pseudonymValue (e.g. TST-a1cd75fe29c449248cabfae)
-
correctPseudonymLength
Corrects the length of the generated pseudonym.- Parameters:
pseudonym- the pseudonym to work with- Returns:
- the length-corrected pseudonym
-
addCheckDigit
public String addCheckDigit(String pseudonym, boolean addInsteadOfLastChar, String domainName, String domainPrefix) Method to add a check digit (or check character) to a pseudonym.- Parameters:
pseudonym- the pseudonym for which a checksum should be generatedaddInsteadOfLastChar- decides whether the checksum should be included in the predefined length of the pseudonym or if it should be an additional characterdomainName- the name of this pseudonym's domaindomainPrefix- the prefix for this pseudonym's domain (including the hyphen, if existing)- Returns:
- the pseudonym including the checksum
-
addPadding
A method to add padding to a given pseudonym. The padding will be added at the start of the string. If the input is longer than the defined length after padding, no padding (and no shortening) is performed.- Parameters:
pseudonym- the pseudonym that should be paddedlengthAfterPadding- how long the output string should bepaddingChar- the character that is used to pad the string- Returns:
- the padded pseudonym
-
persist
public boolean persist()Method to persist the consecutive value in the database.- Returns:
trueif the counter was successfully stored,falseotherwise
-