Skip to content

Simple hashing | Algorithms

Black_Baroness edited this page Sep 1, 2022 · 1 revision

com.github.BlackBaroness.cryptography.hashing.alrogithm contains a lot of hashing families. Their use is as simple as possible, you should not have any problems.

For example, Adler32 is not a family - it is a single algorithm, so it is easiest to use:

HashResult result = new Adler32().hash(hashSource);

Families are usually just classes containing several algorithms inside:

HashResult result = new Sha().sha256().hash(hashSource);

Keep in mind that these classes can be reused many times and distributed across multiple threads.

You can also drop the family and only use a specific algorithm:

HashAlgorithm algorithm = new Md().md5();
ExecutorService threadPool = Executors.newFixedThreadPool(15);
IntStream.range(0, 100)
    .mapToObj(i -> HashSources.ofString(String.valueOf(i)))
    .map(hashSource -> (Runnable) () -> System.out.println(algorithm.hash(hashSource).string()))
    .forEach(threadPool::submit);

As you can see, we took the algorithm and calmly used it in a multi-threaded environment.

Clone this wiki locally