1 package net.sourceforge.jcetaglib.tools; 2 3 import javax.crypto.Mac; 4 import java.io.FilterInputStream ; 5 import java.io.IOException ; 6 import java.io.InputStream ; 7 8 11 12 13 public class MacInputStream extends FilterInputStream { 14 private Mac mac = null; 15 16 public MacInputStream(InputStream st, 17 Mac mac) { 18 super(st); 19 this.mac = mac; 20 } 21 22 public int read() 23 throws IOException { 24 int n = in.read(); 25 if (n > -1) { 26 mac.update((byte) n); 27 } 28 29 return (n); 30 } 31 32 public int read(byte[] b) 33 throws IOException { 34 int n = in.read(b); 35 if (n > -1) { 36 mac.update(b, 0, n); 37 } 38 39 return (n); 40 } 41 42 public int read(byte[] b, 43 int o, 44 int l) 45 throws IOException { 46 int n = in.read(b, o, l); 47 if (n > -1) { 48 mac.update(b, o, n); 49 } 50 51 return (n); 52 } 53 } 54 | Popular Tags |