Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2023 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
*/
package com.itextpdf.kernel.crypto.securityhandler;
import com.itextpdf.kernel.crypto.IDecryptor;
import com.itextpdf.kernel.crypto.OutputStreamEncryption;
import com.itextpdf.kernel.crypto.OutputStreamStandardEncryption;
import com.itextpdf.kernel.crypto.StandardDecryptor;
import com.itextpdf.kernel.pdf.PdfArray;
import com.itextpdf.kernel.pdf.PdfDictionary;
import com.itextpdf.kernel.pdf.PdfName;
import com.itextpdf.kernel.pdf.PdfNumber;
import com.itextpdf.kernel.security.IExternalDecryptionProcess;
import java.io.OutputStream;
import java.security.Key;
import java.security.cert.Certificate;
public class PubSecHandlerUsingStandard40 extends PubKeySecurityHandler {
public PubSecHandlerUsingStandard40(PdfDictionary encryptionDictionary, Certificate[] certs, int[] permissions, boolean encryptMetadata, boolean embeddedFilesOnly) {
initKeyAndFillDictionary(encryptionDictionary, certs, permissions, encryptMetadata, embeddedFilesOnly);
}
public PubSecHandlerUsingStandard40(PdfDictionary encryptionDictionary, Key certificateKey, Certificate certificate,
String certificateKeyProvider, IExternalDecryptionProcess externalDecryptionProcess,
boolean encryptMetadata) {
initKeyAndReadDictionary(encryptionDictionary, certificateKey, certificate, certificateKeyProvider,
externalDecryptionProcess, encryptMetadata);
}
@Override
public OutputStreamEncryption getEncryptionStream(OutputStream os) {
return new OutputStreamStandardEncryption(os, nextObjectKey, 0, nextObjectKeySize);
}
@Override
public IDecryptor getDecryptor() {
return new StandardDecryptor(nextObjectKey, 0, nextObjectKeySize);
}
protected String getDigestAlgorithm() {
return "SHA-1";
}
protected void initKey(byte[] globalKey, int keyLength) {
mkey = new byte[keyLength / 8];
System.arraycopy(globalKey, 0, mkey, 0, mkey.length);
}
protected void setPubSecSpecificHandlerDicEntries(PdfDictionary encryptionDictionary, boolean encryptMetadata, boolean embeddedFilesOnly) {
encryptionDictionary.put(PdfName.Filter, PdfName.Adobe_PubSec);
encryptionDictionary.put(PdfName.R, new PdfNumber(2));
PdfArray recipients = createRecipientsArray();
encryptionDictionary.put(PdfName.V, new PdfNumber(1));
encryptionDictionary.put(PdfName.SubFilter, PdfName.Adbe_pkcs7_s4);
encryptionDictionary.put(PdfName.Recipients, recipients);
}
}