Class Pseudonymizer

java.lang.Object
org.trustdeck.algorithms.Pseudonymizer
Direct Known Subclasses:
BLAKE3Pseudonymizer, ConsecutivePseudonymizer, MD5Pseudonymizer, RandomAlphabetPseudonymizer, RandomNumberPseudonymizer, SHA1Pseudonymizer, SHA2Pseudonymizer, SHA3Pseudonymizer, XxHashPseudonymizer

public abstract class Pseudonymizer extends Object
An abstract class for different pseudonymization algorithms
Author:
Armin Müller
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Determines the default number of retries when a generated random number is already in use.
    static final char
    The default character used for the padding of the generated pseudonyms.
    static final int
    The standard length for the generated pseudonyms.
    static final String
    String to determine that a domain reaches its filling point at which new pseudonyms are not reasonably probable generated anymore.
    static final String
    String to determine that a pseudonymization process failed.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Basic 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 Type
    Method
    Description
    addCheckDigit(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.
    Corrects the length of the generated pseudonym.
    boolean
    Method to persist the consecutive value in the database.
    abstract String
    pseudonymize(String identifier, String domainPrefix)
    Abstract method for the pseudonymization of an identifier.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_VALUE_LENGTH

      public static final int DEFAULT_VALUE_LENGTH
      The standard length for the generated pseudonyms.
      See Also:
    • DEFAULT_PADDING_CHAR

      public static final char DEFAULT_PADDING_CHAR
      The default character used for the padding of the generated pseudonyms.
      See Also:
    • DEFAULT_NUMBER_OF_RETRIES

      public static final int DEFAULT_NUMBER_OF_RETRIES
      Determines the default number of retries when a generated random number is already in use.
      See Also:
    • DOMAIN_FULL

      public static final String 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

      public static final String 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

      public Pseudonymizer(String domainName)
      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 length
      pseudonymValueLength - the desired length of the pseudonym value
      paddingChar - the character that should be used for padding
      domainName - the name of the domain to which the record belongs to
    • Pseudonymizer

      public Pseudonymizer(boolean paddingWanted, Domain domain)
      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 length
      domain - the domain object containing the necessary configuration information
    • Pseudonymizer

      public Pseudonymizer(boolean paddingWanted, Algorithm algorithm)
      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 length
      algorithm - the algorithm object containing the necessary configuration information
  • Method Details

    • pseudonymize

      public abstract String pseudonymize(String identifier, String domainPrefix)
      Abstract method for the pseudonymization of an identifier.
      Parameters:
      identifier - the value to be pseudonymized
      domainPrefix - the prefix for the domain
      Returns:
      a pseudonym in the form of domainPrefix-pseudonymValue (e.g. TST-a1cd75fe29c449248cabfae)
    • correctPseudonymLength

      public String correctPseudonymLength(String pseudonym)
      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 generated
      addInsteadOfLastChar - decides whether the checksum should be included in the predefined length of the pseudonym or if it should be an additional character
      domainName - the name of this pseudonym's domain
      domainPrefix - the prefix for this pseudonym's domain (including the hyphen, if existing)
      Returns:
      the pseudonym including the checksum
    • addPadding

      public String addPadding(String pseudonym, int lengthAfterPadding, char paddingChar)
      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 padded
      lengthAfterPadding - how long the output string should be
      paddingChar - 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:
      true if the counter was successfully stored, false otherwise