Skip to content

Latest commit

 

History

History
24 lines (18 loc) · 598 Bytes

README.md

File metadata and controls

24 lines (18 loc) · 598 Bytes

digest

Digest - hash calculator from inputStream

Proof of concept. Easy way to calculate hash from a inputStream and feed MessageDigest while consume it.

InputStream is = new DigestInputStream(byteArrayInputStream, digest);

Digest digest = new Digest()
    .withAlgorithm(Algorithm.SHA1)
    .withInputStream(is)
    .initialize();

int ch;
//While consuming the inputStream, it feeds the MessageDigest to calculate the Hash
while( (ch = inputStream.read()) != -1) {
    System.out.print((char)ch);
}

inputStream.close();

//calculate hash
String hash = digest.calculateHash();