Created
April 8, 2014 09:13
-
-
Save bobbyjam99-zz/10103580 to your computer and use it in GitHub Desktop.
POIでファイルにパスワード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sample.poi; | |
import java.io.FileOutputStream; | |
import java.io.OutputStream; | |
import org.apache.poi.openxml4j.opc.OPCPackage; | |
import org.apache.poi.poifs.crypt.EncryptionInfo; | |
import org.apache.poi.poifs.crypt.EncryptionMode; | |
import org.apache.poi.poifs.crypt.Encryptor; | |
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |
public class App { | |
public static void main(String[] args) throws Exception { | |
POIFSFileSystem fs = new POIFSFileSystem(); | |
EncryptionInfo info = new EncryptionInfo(fs, EncryptionMode.agile); | |
Encryptor enc = info.getEncryptor(); | |
enc.confirmPassword("foobaa"); | |
OPCPackage opc = OPCPackage.open("/path/to/file"); | |
OutputStream os = enc.getDataStream(fs); | |
opc.save(os); | |
opc.close(); | |
FileOutputStream fos = new FileOutputStream("/path/to/encfile"); | |
fs.writeFilesystem(fos); | |
fos.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment