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

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

Introduction

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

Prototype

public int doFinal(byte[] out, int outOffset) 

Source Link

Document

close the digest, producing the final digest value.

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);
    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   ww w  .j av  a2 s.  c  om*/

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