1package org.bouncycastle.crypto.io; 2 3import java.io.IOException; 4import java.io.OutputStream; 5 6import org.bouncycastle.crypto.Digest; 7 8public class DigestOutputStream 9 extends OutputStream 10{ 11 protected Digest digest; 12 13 public DigestOutputStream( 14 Digest Digest) 15 { 16 this.digest = Digest; 17 } 18 19 public void write(int b) 20 throws IOException 21 { 22 digest.update((byte)b); 23 } 24 25 public void write( 26 byte[] b, 27 int off, 28 int len) 29 throws IOException 30 { 31 digest.update(b, off, len); 32 } 33 34 public byte[] getDigest() 35 { 36 byte[] res = new byte[digest.getDigestSize()]; 37 38 digest.doFinal(res, 0); 39 40 return res; 41 } 42} 43