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

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

Introduction

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

Prototype

public Blake2bDigest(byte[] key) 

Source Link

Document

Blake2b for authentication ("Prefix-MAC mode").

Usage

From source file:com.distrimind.util.crypto.BCMac.java

License:Open Source License

public void init(org.bouncycastle.crypto.SymmetricSecretKey _key) throws NoSuchAlgorithmException {
    Digest d;//from   www  . j a v  a 2s . c o  m
    if (type.getCodeProviderForSignature() == CodeProvider.BC) {
        switch (type.getMessageDigestType()) {
        case BC_FIPS_SHA3_256:
            d = new SHA3Digest(256);
            break;
        case BC_FIPS_SHA3_384:
            d = new SHA3Digest(384);
            break;
        case BC_FIPS_SHA3_512:
            d = new SHA3Digest(512);
            break;
        case BC_BLAKE2B_160:
        case BC_BLAKE2B_256:
        case BC_BLAKE2B_384:
        case BC_BLAKE2B_512:
            d = new Blake2bDigest(type.getMessageDigestType().getDigestLengthInBits());
            break;
        default:
            throw new NoSuchAlgorithmException(type.toString());
        }
    } else {
        throw new NoSuchAlgorithmException(type.toString());
    }
    mac = new HMac(d);
    mac.init(new KeyParameter((secretKey = _key).getKeyBytes()));
    reset();

}

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);//ww w.j  ava  2s . c o  m
    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);
    }//  ww  w  .  ja v a2s .  c o m

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