Hello,
I've got a probleme when I use the Self_sign mode it says that :
ExceptionConverter:
java.security.InvalidKeyException: Private keys must be instance of
RSAPrivate(Crt)Key or have PKCS#8 encoding
The huge thing is when I use the Veri_sign mode it works fine (the probleme is
when I open with adobe, ask me for a plug in)...
Any help would be very appreciated.
Arun.
ps. In case it helps. here is my code:
KeyStore ks;
Provider p;
try {
String config="name=p11\nlibrary=netp11.dll\ndescription=Hardware
device config";
InputStream is2 = new ByteArrayInputStream(config.getBytes());
p = new sun.security.pkcs11.SunPKCS11(is2);
Security.addProvider(p);
System.out.println( Security.getProviders());
// Creation d'un KeyStore
ks = KeyStore.getInstance("PKCS11");
// Chargement du certificat p11 dans le magasin
ks.load(null,null);//filekey filepassword
// Recupération de l'alias
Enumeration<String> as1 = ks.aliases();
System.out.println("Enumeration alias: "+as1);
String alias = null;
while(as1.hasMoreElements()){
String ss = as1.nextElement();
X509Certificate cert2 = (X509Certificate)ks.getCertificate(ss);
if (cert2.getSubjectAlternativeNames()!=null)
{
alias=ss;
System.out.println(cert2.toString());
System.out.println(cert2.getPublicKey().toString());
}
}
System.out.println("alias: "+alias);
// Recupération de la clé privée
PrivateKey key = (PrivateKey)ks.getKey(alias, null);
System.out.println("key Algorithm: "+key.getAlgorithm());
System.out.println("key Format: "+key.getFormat());
System.out.println("key: "+key.toString());
// et de la chaine de certificats
Certificate[] chain = ks.getCertificateChain(alias);
System.out.println("cert: "+chain.toString());
PdfReader pdfReader = new PdfReader((new
File(fname)).getAbsolutePath());
FileOutputStream output = new FileOutputStream(fnameSlocal);
Calendar cal = Calendar.getInstance();
PdfStamper pdfStamper;
pdfStamper = PdfStamper.createSignature(pdfReader,output,'\0');
PdfSignatureAppearance sap = pdfStamper.getSignatureAppearance();
sap.setCrypto(key, chain, null,
PdfSignatureAppearance.VERISIGN_SIGNED);//SELF_SIGNED
sap.setReason("Test Sign Pdf");
//sap.setLocation("");
sap.setCertificationLevel(PdfSignatureAppearance.CERTIFIED_NO_CHANGES_ALLOWED);
sap.setSignDate(cal);
sap.setVisibleSignature(new Rectangle(100, 100, 200, 200), 1, null);
pdfStamper.setFormFlattening(true);
pdfStamper.close();
System.out.println("docs signé");
return true;
}
catch (Exception key) {
System.out.println("Impossible to sign PDF"+key.toString());
throw new Exception(key);
}
}
_________________________________________________________________
Inédit ! Des Emoticônes Déjantées! Installez les dans votre Messenger !
http://www.ilovemessenger.fr/Emoticones/EmoticonesDejantees.aspx------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php