1 import org.faceless.pdf2.*; 2 import java.io.*; 3 import java.util.zip.CRC32 ; 4 import java.security.KeyStore ; 5 import java.security.GeneralSecurityException ; 6 7 public class DummySignatureHandler extends SignatureHandler 11 { 12 public DummySignatureHandler() 13 { 14 super(); 15 } 16 17 public String getFilter() 18 { 19 return "Dummy.CRC32"; 20 } 21 22 protected void prepareToSign(KeyStore store, String alias, char[] password) 23 throws GeneralSecurityException 24 { 25 super.prepareToSign(store, alias, password); 27 putNumericValue("Version", 1); } 29 30 public byte[] sign(InputStream in) 31 { 32 CRC32 crc = new CRC32 (); 33 int b; 34 try { 35 while ((b=in.read())>=0) { 36 crc.update(b); 37 } 38 } catch (IOException e) { 39 throw new RuntimeException ("Unexpected IOException!"); 40 } 41 int val = (int)crc.getValue(); 42 byte[] out = new byte[4]; 43 out[0]=(byte)(val>>24); 44 out[1]=(byte)(val>>16); 45 out[2]=(byte)(val>>8); 46 out[3]=(byte)(val); 47 return out; 48 } 49 50 public boolean verify(InputStream in) 51 { 52 CRC32 crc = new CRC32 (); 53 int b; 54 try { 55 while ((b=in.read())>=0) { 56 crc.update(b); 57 } 58 } catch (IOException e) { 59 throw new RuntimeException ("Unexpected IOException!"); 60 } 61 int val = (int)crc.getValue(); 62 byte[] buf = getStringValue("Contents"); 63 return val == ((buf[0]<<24 & 0xff000000) + 64 (buf[1]<<16 & 0xff0000) + 65 (buf[2]<<8 & 0xff00) + 66 (buf[3] & 0xff)); 67 } 68 69 public String [] getLayerNames() 70 { 71 final String [] names = { "n0" }; 72 return names; 73 } 74 75 public PDFCanvas getLayerAppearance(String name, PDFStyle style) 76 { 77 if (name.equals("n0")) { 78 PDFCanvas canvas = new PDFCanvas(100, 100); 79 canvas.setStyle(style); 80 LayoutBox box = new LayoutBox(80); 81 box.addTextNoBreak("CRC-32", style, null); 82 canvas.drawLayoutBox(box, 10, 50); 83 return canvas; 84 } else { 85 throw new IllegalArgumentException ("Unknown layer '"+name+"' requested"); 88 } 89 } 90 } 91 | Popular Tags |