Hi Guys, I started developing for Android using iText,I used to develop only
for web servers using iText, but now I'm having some issues with signing
documents using iText in AndroidI'm only running texts by far but I already
found some problems... Usually when I close the Stamper
Here is The Code:
private static String passStore = "passStore"; private static String passKey =
"passKey"; private KeyStore ks; private PrivateKey key; private
Certificate[] chain; @Override public void onCreate(Bundle
savedInstanceState) { try{ Bitmap bitmap =
((BitmapDrawable)getResources().getDrawable(R.drawable.logo)).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); byte[]
bitmapdata = stream.toByteArray();
super.onCreate(savedInstanceState); setContentView(R.layout.main);
String file = Environment.getExternalStorageDirectory()+
File.separator + "text.pdf"; String dest =
Environment.getExternalStorageDirectory()+ File.separator + "Signed.pdf";
Document doc = new Document(); PdfWriter.getInstance(doc, new
FileOutputStream(file)); doc.open(); doc.add(new
Paragraph("Test")); doc.close();
keys(); PdfReader reader
= new PdfReader(file); FileOutputStream os = new
FileOutputStream(dest); PdfStamper stamper =
PdfStamper.createSignature(reader, os, '\0');
PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
appearance.setCrypto(key, chain, null,PdfSignatureAppearance.WINCER_SIGNED);
appearance.setImage(Image.getInstance(bitmapdata));
appearance.setReason("4Fun"); appearance.setLocation("Here");
appearance.setVisibleSignature(new Rectangle(72, 732, 144, 780), 1,
"Andre"); stamper.close();
}catch(Exception e){
System.out.println(e.getMessage()); } } private void
keys() throws Exception{ AssetManager assetManager = this.getAssets();
String[] files = assetManager.list(""); for(int i = 0 ; i <
files.length;i++){ if(files[i].contains("keys")){
ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(assetManager.open(files[i]),passStore.toCharArray());
key = (PrivateKey) ks.getKey("andre_mariano", passKey.toCharArray());
chain = ks.getCertificateChain("andre_mariano");
break; } } }
Here is The Error:Throw some "NoSuchFieldError" on
PdfPKCS7.getEncodedPKCS7(byte[], Calendar, TSAClient, byte[]) line: 1200
--java.lang.NoSuchFieldError: org.bouncycastle.asn1.DERNull.INSTANCE
iText Version: 5.1.1Android Version: 2.2Keystore Type: BKSKey Encryptation: RSA
(2048 bits) ------------------------------------------------------------------------------
10 Tips for Better Web Security
Learn 10 ways to better secure your business today. Topics covered include:
Web security, SSL, hacker attacks & Denial of Service (DoS), private keys,
security Microsoft Exchange, secure Instant Messaging, and much more.
http://www.accelacomm.com/jaw/sfnl/114/51426210/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php