Class ControlNumberGenerator
- java.lang.Object
-
- de.pseudonymisierung.controlnumbers.ControlNumberGenerator
-
- All Implemented Interfaces:
java.util.function.Function<String,ControlNumber>
- Direct Known Subclasses:
EncryptedControlNumberGenerator
public class ControlNumberGenerator extends Object implements java.util.function.Function<String,ControlNumber>
Generator for "simple" control number, i.e. without encryption by a secret key. Usebuilder()to get aControlNumberGenerator.Builderinstance, which has methods for setting various parameters.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classControlNumberGenerator.AbstractBuilder<T extends ControlNumberGenerator>Abstraction of a builder class.static classControlNumberGenerator.BuilderBuilder for simple control number generators (i.e.
-
Field Summary
Fields Modifier and Type Field Description static CharsetdefaultEncodingDefault encoding to use when transforming input strings to byte sequences (necessery for applying hash functions and encryption).static intdefaultHashLengthDefault bit lenght of control numbers.static intdefaultNGramLengthDefault length of n-grams (2 -> bigrams).static intdefaultNHashFunctionsDefault number of hash functions.protected Charsetencoding
-
Constructor Summary
Constructors Modifier Constructor Description protectedControlNumberGenerator(ControlNumberGenerator.AbstractBuilder<?> builder)Constructor, called byControlNumberGenerator.Builder.build().
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ControlNumberapply(String input)Calculate a control number from an input string.static ControlNumberGenerator.Builderbuilder()Get a builder object with methods to set parameters to non-default values and to get the resulting instance ofControlNumberGenerator.protected byte[]getMd5Hash(String input)Get MD5 hash of a string.protected byte[]getSha1Hash(String input)Get SHA1 hash of a string.protected inthash(byte[] basehash1, byte[] baseHash2, int index)
-
-
-
Field Detail
-
defaultHashLength
public static final int defaultHashLength
Default bit lenght of control numbers.- See Also:
- Constant Field Values
-
defaultNGramLength
public static final int defaultNGramLength
Default length of n-grams (2 -> bigrams).- See Also:
- Constant Field Values
-
defaultNHashFunctions
public static final int defaultNHashFunctions
Default number of hash functions.- See Also:
- Constant Field Values
-
defaultEncoding
public static final Charset defaultEncoding
Default encoding to use when transforming input strings to byte sequences (necessery for applying hash functions and encryption).
-
encoding
protected Charset encoding
-
-
Constructor Detail
-
ControlNumberGenerator
protected ControlNumberGenerator(ControlNumberGenerator.AbstractBuilder<?> builder)
Constructor, called byControlNumberGenerator.Builder.build().- Parameters:
builder- The builder object from which to create the instance.
-
-
Method Detail
-
builder
public static ControlNumberGenerator.Builder builder()
Get a builder object with methods to set parameters to non-default values and to get the resulting instance ofControlNumberGenerator.- Returns:
- An instance of
ControlNumberGenerator.Builder
-
apply
public ControlNumber apply(String input)
Calculate a control number from an input string.- Specified by:
applyin interfacejava.util.function.Function<String,ControlNumber>- Parameters:
input- The character string to encode.- Returns:
- The resulting control number.
-
getMd5Hash
protected byte[] getMd5Hash(String input)
Get MD5 hash of a string. This is one of the base hash functions from which the desired number of hashes is calculated. The base hashes are defined as protected methods so thatEncryptedControlNumberGeneratoronly needs to override these using keyed hash functions.- Parameters:
input- The character string to encode.- Returns:
- The resulting hash.
-
getSha1Hash
protected byte[] getSha1Hash(String input)
Get SHA1 hash of a string.- See Also:
for more information.
-
hash
protected int hash(byte[] basehash1, byte[] baseHash2, int index)
-
-