org.bouncycastle.crypto.digests.Prehash Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcprov-jdk14 Show documentation
Show all versions of bcprov-jdk14 Show documentation
The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.4.
package org.bouncycastle.crypto.digests;
import org.bouncycastle.crypto.Digest;
import org.bouncycastle.util.io.LimitedBuffer;
public class Prehash
implements Digest
{
public static Prehash forDigest(Digest digest)
{
return new Prehash(digest);
}
private final String algorithmName;
private final LimitedBuffer buf;
private Prehash(Digest digest)
{
algorithmName = digest.getAlgorithmName();
buf = new LimitedBuffer(digest.getDigestSize());
}
public String getAlgorithmName()
{
return algorithmName;
}
public int getDigestSize()
{
return buf.limit();
}
public void update(byte in)
{
buf.write(in);
}
public void update(byte[] in, int inOff, int len)
{
buf.write(in, inOff, len);
}
public int doFinal(byte[] out, int outOff)
{
try
{
if (getDigestSize() != buf.size())
{
throw new IllegalStateException("Incorrect prehash size");
}
return buf.copyTo(out, outOff);
}
finally
{
reset();
}
}
public void reset()
{
buf.reset();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy