MCPcopy Create free account
hub / github.com/apache/pdfbox / call

Method call

tools/src/main/java/org/apache/pdfbox/tools/Encrypt.java:128–196  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

126 }
127
128 public Integer call()
129 {
130 AccessPermission ap = new AccessPermission();
131 ap.setCanAssembleDocument(canAssembleDocument);
132 ap.setCanExtractContent(canExtractContent);
133 ap.setCanExtractForAccessibility(canExtractForAccessibility);
134 ap.setCanFillInForm(canFillInForm);
135 ap.setCanModify(canModify);
136 ap.setCanModifyAnnotations(canModifyAnnotations);
137 ap.setCanPrint(canPrint);
138 ap.setCanPrintFaithful(canPrintFaithful);
139
140 if (outfile == null)
141 {
142 outfile = infile;
143 }
144
145 try (PDDocument document = Loader.loadPDF(infile))
146 {
147 if( !document.isEncrypted() )
148 {
149 if (!document.getSignatureDictionaries().isEmpty())
150 {
151 SYSERR.println( "Warning: Document contains signatures which will be invalidated by encryption." );
152 }
153
154 if (!certFileList.isEmpty())
155 {
156 PublicKeyProtectionPolicy ppp = new PublicKeyProtectionPolicy();
157 PublicKeyRecipient recip = new PublicKeyRecipient();
158 recip.setPermission(ap);
159
160 CertificateFactory cf = CertificateFactory.getInstance("X.509");
161
162 for (File certFile : certFileList)
163 {
164 try (InputStream inStream = new FileInputStream(certFile))
165 {
166 X509Certificate certificate = (X509Certificate) cf.generateCertificate(inStream);
167 recip.setX509(certificate);
168 }
169 ppp.addRecipient(recip);
170 }
171
172 ppp.setEncryptionKeyLength(keyLength);
173
174 document.protect(ppp);
175 }
176 else
177 {
178 StandardProtectionPolicy spp =
179 new StandardProtectionPolicy(ownerPassword, userPassword, ap);
180 spp.setEncryptionKeyLength(keyLength);
181 document.protect(spp);
182 }
183 document.save( outfile );
184 }
185 else

Callers

nothing calls this directly

Calls 15

setCanExtractContentMethod · 0.95
setCanFillInFormMethod · 0.95
setCanModifyMethod · 0.95
setCanPrintMethod · 0.95
setCanPrintFaithfulMethod · 0.95
loadPDFMethod · 0.95
setPermissionMethod · 0.95
setX509Method · 0.95
addRecipientMethod · 0.95

Tested by

no test coverage detected