Example usage for org.bouncycastle.crypto.digests Blake2bDigest getDigestSize

List of usage examples for org.bouncycastle.crypto.digests Blake2bDigest getDigestSize

Introduction

In this page you can find the example usage for org.bouncycastle.crypto.digests Blake2bDigest getDigestSize.

Prototype

public int getDigestSize() 

Source Link

Document

return the size, in bytes, of the digest produced by this message digest.

Usage

From source file:org.apache.nifi.security.util.crypto.HashService.java

License:Apache License

private static byte[] blake2Hash(HashAlgorithm algorithm, byte[] value) {
    int digestLengthBytes = algorithm.getDigestBytesLength();
    Blake2bDigest blake2bDigest = new Blake2bDigest(digestLengthBytes * 8);
    byte[] rawHash = new byte[blake2bDigest.getDigestSize()];
    blake2bDigest.update(value, 0, value.length);
    blake2bDigest.doFinal(rawHash, 0);//from   www  .j a va  2 s. com
    return rawHash;
}

From source file:org.apache.nifi.security.util.crypto.HashService.java

License:Apache License

private static byte[] blake2HashStreaming(HashAlgorithm algorithm, InputStream value) throws IOException {
    int digestLengthBytes = algorithm.getDigestBytesLength();
    Blake2bDigest blake2bDigest = new Blake2bDigest(digestLengthBytes * 8);
    byte[] rawHash = new byte[blake2bDigest.getDigestSize()];

    final byte[] buffer = new byte[BUFFER_SIZE];
    int read = value.read(buffer, 0, BUFFER_SIZE);

    while (read > -1) {
        blake2bDigest.update(buffer, 0, read);
        read = value.read(buffer, 0, BUFFER_SIZE);
    }/*from   w  w  w.j  ava 2s.c o m*/

    blake2bDigest.doFinal(rawHash, 0);
    return rawHash;
}