use of org.apache.poi.poifs.crypt.Encryptor in project poi by apache.
the class XOREncryptionInfoBuilder method initialize.
@Override
public void initialize(EncryptionInfo info, CipherAlgorithm cipherAlgorithm, HashAlgorithm hashAlgorithm, int keyBits, int blockSize, ChainingMode chainingMode) {
info.setHeader(new XOREncryptionHeader());
info.setVerifier(new XOREncryptionVerifier());
Decryptor dec = new XORDecryptor();
dec.setEncryptionInfo(info);
info.setDecryptor(dec);
Encryptor enc = new XOREncryptor();
enc.setEncryptionInfo(info);
info.setEncryptor(enc);
}
use of org.apache.poi.poifs.crypt.Encryptor in project poi by apache.
the class InternalWorkbook method updateEncryptionRecord.
private void updateEncryptionRecord() {
FilePassRecord fpr = (FilePassRecord) findFirstRecordBySid(FilePassRecord.sid);
String password = Biff8EncryptionKey.getCurrentUserPassword();
if (password == null) {
if (fpr != null) {
// need to remove password data
records.remove(fpr);
}
} else {
// create password record
if (fpr == null) {
fpr = new FilePassRecord(EncryptionMode.binaryRC4);
records.add(1, fpr);
}
// check if the password has been changed
EncryptionInfo ei = fpr.getEncryptionInfo();
byte[] encVer = ei.getVerifier().getEncryptedVerifier();
try {
Decryptor dec = ei.getDecryptor();
Encryptor enc = ei.getEncryptor();
if (encVer == null || !dec.verifyPassword(password)) {
enc.confirmPassword(password);
} else {
SecretKey sk = dec.getSecretKey();
ei.getEncryptor().setSecretKey(sk);
}
} catch (GeneralSecurityException e) {
throw new EncryptedDocumentException("can't validate/update encryption setting", e);
}
}
}
use of org.apache.poi.poifs.crypt.Encryptor in project poi by apache.
the class TestXSLFSlideShowFactory method createProtected.
private static File createProtected(String basefile, String password) throws IOException, GeneralSecurityException {
NPOIFSFileSystem fs = new NPOIFSFileSystem();
EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile);
Encryptor enc = info.getEncryptor();
enc.confirmPassword(password);
InputStream fis = _slTests.openResourceAsStream(basefile);
OutputStream os = enc.getDataStream(fs);
IOUtils.copy(fis, os);
os.close();
fis.close();
File tf = TempFile.createTempFile("test-xslf-slidefactory", ".pptx");
FileOutputStream fos = new FileOutputStream(tf);
fs.writeFilesystem(fos);
fos.close();
fs.close();
return tf;
}
use of org.apache.poi.poifs.crypt.Encryptor in project poi by apache.
the class SavePasswordProtectedXlsx method save.
public static void save(final InputStream inputStream, final String filename, final String pwd) throws InvalidFormatException, IOException, GeneralSecurityException {
POIFSFileSystem fs = null;
FileOutputStream fos = null;
OPCPackage opc = null;
try {
fs = new POIFSFileSystem();
EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile);
Encryptor enc = Encryptor.getInstance(info);
enc.confirmPassword(pwd);
opc = OPCPackage.open(inputStream);
fos = new FileOutputStream(filename);
opc.save(enc.getDataStream(fs));
fs.writeFilesystem(fos);
} finally {
IOUtils.closeQuietly(fos);
IOUtils.closeQuietly(opc);
IOUtils.closeQuietly(fs);
IOUtils.closeQuietly(inputStream);
}
}
use of org.apache.poi.poifs.crypt.Encryptor in project poi by apache.
the class XOREncryptionInfoBuilder method initialize.
@Override
public void initialize(EncryptionInfo info, LittleEndianInput dis) throws IOException {
info.setHeader(new XOREncryptionHeader());
info.setVerifier(new XOREncryptionVerifier(dis));
Decryptor dec = new XORDecryptor();
dec.setEncryptionInfo(info);
info.setDecryptor(dec);
Encryptor enc = new XOREncryptor();
enc.setEncryptionInfo(info);
info.setEncryptor(enc);
}
Aggregations