Class ShortenedDigest

  • All Implemented Interfaces:
    Digest, ExtendedDigest

    public class ShortenedDigest
    extends Object
    implements ExtendedDigest
    Wrapper class that reduces the output length of a particular digest to only the first n bytes of the digest function.
    • Constructor Detail

      • ShortenedDigest

        public ShortenedDigest​(ExtendedDigest baseDigest,
                               int length)
        Base constructor.
        Parameters:
        baseDigest - underlying digest to use.
        length - length in bytes of the output of doFinal.
        Throws:
        IllegalArgumentException - if baseDigest is null, or length is greater than baseDigest.getDigestSize().
    • Method Detail

      • getAlgorithmName

        public String getAlgorithmName()
        Description copied from interface: Digest
        return the algorithm name
        Specified by:
        getAlgorithmName in interface Digest
        Returns:
        the algorithm name
      • getDigestSize

        public int getDigestSize()
        Description copied from interface: Digest
        return the size, in bytes, of the digest produced by this message digest.
        Specified by:
        getDigestSize in interface Digest
        Returns:
        the size, in bytes, of the digest produced by this message digest.
      • update

        public void update​(byte in)
        Description copied from interface: Digest
        update the message digest with a single byte.
        Specified by:
        update in interface Digest
        Parameters:
        in - the input byte to be entered.
      • update

        public void update​(byte[] in,
                           int inOff,
                           int len)
        Description copied from interface: Digest
        update the message digest with a block of bytes.
        Specified by:
        update in interface Digest
        Parameters:
        in - the byte array containing the data.
        inOff - the offset into the byte array where the data starts.
        len - the length of the data.
      • doFinal

        public int doFinal​(byte[] out,
                           int outOff)
        Description copied from interface: Digest
        close the digest, producing the final digest value. The doFinal call leaves the digest reset.
        Specified by:
        doFinal in interface Digest
        Parameters:
        out - the array the digest is to be copied into.
        outOff - the offset into the out array the digest is to start at.
      • reset

        public void reset()
        Description copied from interface: Digest
        reset the digest back to it's initial state.
        Specified by:
        reset in interface Digest
      • getByteLength

        public int getByteLength()
        Description copied from interface: ExtendedDigest
        Return the size in bytes of the internal buffer the digest applies it's compression function to.
        Specified by:
        getByteLength in interface ExtendedDigest
        Returns:
        byte length of the digests internal buffer.