Example usage for org.bouncycastle.crypto.digests GeneralDigest reset

List of usage examples for org.bouncycastle.crypto.digests GeneralDigest reset

Introduction

In this page you can find the example usage for org.bouncycastle.crypto.digests GeneralDigest reset.

Prototype

public void reset() 

Source Link

Usage

From source file:com.stg.crypto.IODigestUtility.java

License:Open Source License

/**
 * Wraps the given {@link InputStream} against a digest
 * @param is input stream// ww w  .  j av  a 2  s .c o m
 * @return input stream
 */
public static DigestInputStream wrapDigestInputStream(GeneralDigest digest, InputStream is) {
    digest.reset();
    return new DigestInputStream(is, digest);
}

From source file:com.stg.crypto.IODigestUtility.java

License:Open Source License

/**
 * Wraps the given {@link OutputStream} against a digest.
 * /*from   w  w w.  j a  v a  2 s.c  o m*/
 * @param os output stream to be wrapped.
 * @return output stream.
 */
public static DigestOutputStream wrapDigestOutputStream(GeneralDigest digest, OutputStream os) {
    digest.reset();
    return new DigestOutputStream(os, digest);
}

From source file:org.bunkr.cli.commands.HashCommand.java

License:Open Source License

private byte[] calculateHash(ArchiveInfoContext context, FileInventoryItem target, String algorithm,
        boolean showProgress) throws IOException, CLIException {
    ProgressBar pb = new ProgressBar(120, target.getActualSize(), "Calculating hash: ");
    pb.setEnabled(showProgress);//w ww . ja va 2 s. c  o m
    pb.startFresh();
    GeneralDigest digest = getDigest(algorithm);
    digest.reset();
    try (MultilayeredInputStream ms = new MultilayeredInputStream(context, target)) {
        byte[] buffer = new byte[(int) Units.MEBIBYTE];
        int n;
        while ((n = ms.read(buffer)) != -1) {
            digest.update(buffer, 0, n);
            pb.inc(n);
        }
        Arrays.fill(buffer, (byte) 0);
    }
    pb.finish();

    int length = digest.getDigestSize();
    byte[] buffer = new byte[length];
    digest.doFinal(buffer, 0);

    return buffer;
}