import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.security.DigestInputStream;
import java.security.DigestOutputStream;
import java.security.MessageDigest;
public class MainClass {
public static void main(String[] args) throws Exception {
byte[] input = "1234567".getBytes();
MessageDigest hash = MessageDigest.getInstance("SHA1");
ByteArrayInputStream bIn = new ByteArrayInputStream(input);
DigestInputStream dIn = new DigestInputStream(bIn, hash);
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
int ch;
while ((ch = dIn.read()) >= 0) {
bOut.write(ch);
}
byte[] newInput = bOut.toByteArray();
System.out.println("in digest : " + new String(dIn.getMessageDigest().digest()));
DigestOutputStream dOut = new DigestOutputStream( new ByteArrayOutputStream(), hash);
dOut.write(newInput);
dOut.close();
System.out.println("out digest: " + new String(dOut.getMessageDigest().digest()));
}
}