org.spongycastle.openpgp.operator.bc.SHA1PGPDigestCalculator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pg Show documentation
Show all versions of pg Show documentation
Spongy Castle is a package-rename (org.bouncycastle.* to org.spongycastle.*) of Bouncy Castle
intended for the Android platform. Android unfortunately ships with a stripped-down version of
Bouncy Castle, which prevents easy upgrades - Spongy Castle overcomes this and provides a full,
up-to-date version of the Bouncy Castle cryptographic libs.
The newest version!
package org.spongycastle.openpgp.operator.bc;
import java.io.IOException;
import java.io.OutputStream;
import org.spongycastle.bcpg.HashAlgorithmTags;
import org.spongycastle.crypto.Digest;
import org.spongycastle.crypto.digests.SHA1Digest;
import org.spongycastle.openpgp.operator.PGPDigestCalculator;
class SHA1PGPDigestCalculator
implements PGPDigestCalculator
{
private Digest digest = new SHA1Digest();
public int getAlgorithm()
{
return HashAlgorithmTags.SHA1;
}
public OutputStream getOutputStream()
{
return new DigestOutputStream(digest);
}
public byte[] getDigest()
{
byte[] d = new byte[digest.getDigestSize()];
digest.doFinal(d, 0);
return d;
}
public void reset()
{
digest.reset();
}
private class DigestOutputStream
extends OutputStream
{
private Digest dig;
DigestOutputStream(Digest dig)
{
this.dig = dig;
}
public void write(byte[] bytes, int off, int len)
throws IOException
{
dig.update(bytes, off, len);
}
public void write(byte[] bytes)
throws IOException
{
dig.update(bytes, 0, bytes.length);
}
public void write(int b)
throws IOException
{
dig.update((byte)b);
}
}
}