All Downloads are FREE. Search and download functionalities are using the official Maven repository.

eu.mais_h.mathsync.digest.Sha1Digester Maven / Gradle / Ivy

package eu.mais_h.mathsync.digest;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Digester producing SHA-1 digests.
 *
 * 

Retrieve instances of this kind using {@link #get()}.

* * @see Wikipedia's article on SHA-1 */ public class Sha1Digester implements Digester { private static final String DIGEST_ALGORITHM = "SHA-1"; private static final Sha1Digester INSTANCE = new Sha1Digester(); private Sha1Digester() { } /** * Digests according to SHA-1 specification. */ @Override public byte[] digest(byte[] source) { if (source == null) { throw new IllegalArgumentException("Cannot digest null source"); } MessageDigest md; try { md = MessageDigest.getInstance(DIGEST_ALGORITHM); } catch (NoSuchAlgorithmException e) { throw new AssertionError("JVM does not support " + DIGEST_ALGORITHM + " algorithm", e); } md.update(source); return md.digest(); } @Override public String toString() { return DIGEST_ALGORITHM; } /** * Retrieves an instance of this digester kind. * * @return an instance of this digester kind. */ public static Sha1Digester get() { return INSTANCE; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy