use of pdftk.com.lowagie.text.ExceptionConverter in project staplr by pridiltal.
the class PdfPKCS7 method loadCacertsKeyStore.
/**
* Loads the default root certificates at <java.home>/lib/security/cacerts.
* @param provider the provider or <code>null</code> for the default provider
* @return a <CODE>KeyStore</CODE>
*/
public static KeyStore loadCacertsKeyStore(String provider) {
File file = new File(System.getProperty("java.home"), "lib");
file = new File(file, "security");
file = new File(file, "cacerts");
FileInputStream fin = null;
try {
fin = new FileInputStream(file);
KeyStore k;
if (provider == null)
k = KeyStore.getInstance("JKS");
else
k = KeyStore.getInstance("JKS", provider);
k.load(fin, null);
return k;
} catch (Exception e) {
throw new ExceptionConverter(e);
} finally {
try {
fin.close();
} catch (Exception ex) {
}
}
}
use of pdftk.com.lowagie.text.ExceptionConverter in project staplr by pridiltal.
the class PdfPKCS7 method getIssuer.
/**
* Get the "issuer" from the TBSCertificate bytes that are passed in
* @param enc a TBSCertificate in a byte array
* @return a ASN1Primitive
*/
private static ASN1Primitive getIssuer(byte[] enc) {
try {
ASN1InputStream in = new ASN1InputStream(new ByteArrayInputStream(enc));
ASN1Sequence seq = (ASN1Sequence) in.readObject();
return (ASN1Primitive) seq.getObjectAt(seq.getObjectAt(0) instanceof DERTaggedObject ? 3 : 2);
} catch (IOException e) {
throw new ExceptionConverter(e);
}
}
use of pdftk.com.lowagie.text.ExceptionConverter in project staplr by pridiltal.
the class PdfPKCS7 method getEncodedPKCS1.
/**
* Gets the bytes for the PKCS#1 object.
* @return a byte array
*/
public byte[] getEncodedPKCS1() {
try {
if (externalDigest != null)
digest = externalDigest;
else
digest = sig.sign();
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
ASN1OutputStream dout = new ASN1OutputStream(bOut);
dout.writeObject(new DEROctetString(digest));
dout.close();
return bOut.toByteArray();
} catch (Exception e) {
throw new ExceptionConverter(e);
}
}
use of pdftk.com.lowagie.text.ExceptionConverter in project staplr by pridiltal.
the class PdfPKCS7 method getSubject.
/**
* Get the "subject" from the TBSCertificate bytes that are passed in
* @param enc A TBSCertificate in a byte array
* @return a ASN1Primitive
*/
private static ASN1Primitive getSubject(byte[] enc) {
try {
ASN1InputStream in = new ASN1InputStream(new ByteArrayInputStream(enc));
ASN1Sequence seq = (ASN1Sequence) in.readObject();
return (ASN1Primitive) seq.getObjectAt(seq.getObjectAt(0) instanceof DERTaggedObject ? 5 : 4);
} catch (IOException e) {
throw new ExceptionConverter(e);
}
}
use of pdftk.com.lowagie.text.ExceptionConverter in project staplr by pridiltal.
the class PdfStamperImp method alterContents.
void alterContents() throws IOException {
for (Iterator i = pagesToContent.values().iterator(); i.hasNext(); ) {
PageStamp ps = (PageStamp) i.next();
PdfDictionary pageN = ps.pageN;
markUsed(pageN);
PdfArray ar = null;
PdfObject content = PdfReader.getPdfObject(pageN.get(PdfName.CONTENTS), pageN);
if (content == null) {
ar = new PdfArray();
pageN.put(PdfName.CONTENTS, ar);
} else if (content.isArray()) {
ar = (PdfArray) content;
markUsed(ar);
} else if (content.isStream()) {
ar = new PdfArray();
ar.add(pageN.get(PdfName.CONTENTS));
pageN.put(PdfName.CONTENTS, ar);
} else {
ar = new PdfArray();
pageN.put(PdfName.CONTENTS, ar);
}
ByteBuffer out = new ByteBuffer();
if (ps.under != null) {
out.append(PdfContents.SAVESTATE);
applyRotation(pageN, out);
out.append(ps.under.getInternalBuffer());
out.append(PdfContents.RESTORESTATE);
}
if (ps.over != null)
out.append(PdfContents.SAVESTATE);
PdfStream stream = new PdfStream(out.toByteArray());
try {
stream.flateCompress();
} catch (Exception e) {
throw new ExceptionConverter(e);
}
ar.addFirst(addToBody(stream).getIndirectReference());
out.reset();
if (ps.over != null) {
out.append(' ');
out.append(PdfContents.RESTORESTATE);
out.append(PdfContents.SAVESTATE);
applyRotation(pageN, out);
out.append(ps.over.getInternalBuffer());
out.append(PdfContents.RESTORESTATE);
stream = new PdfStream(out.toByteArray());
try {
stream.flateCompress();
} catch (Exception e) {
throw new ExceptionConverter(e);
}
ar.add(addToBody(stream).getIndirectReference());
}
alterResources(ps);
}
}
Aggregations