Sophie

Sophie

distrib > Mageia > 5 > i586 > by-pkgid > e4b7ea989087cb3ab9e6e72793e02115 > files > 8

apache-poi-manual-3.10.1-3.mga5.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!--*** This is a generated file.  Do not edit.  ***-->
<link rel="stylesheet" href="skin/tigris.css" type="text/css">
<link rel="stylesheet" href="skin/mysite.css" type="text/css">
<link rel="stylesheet" href="skin/site.css" type="text/css">
<link media="print" rel="stylesheet" href="skin/print.css" type="text/css">
<title>Apache POI - Encryption support</title>
</head>
<body bgcolor="white" class="composite">
<!--================= start Banner ==================-->
<div id="banner">
<table width="100%" cellpadding="8" cellspacing="0" summary="banner" border="0">
<tbody>
<tr>
<!--================= start Group Logo ==================-->
<td width="50%" align="left">
<div class="groupLogo">
<a href="http://poi.apache.org"><img border="0" class="logoImage" alt="Apache POI" src="resources/images/group-logo.jpg"></a>
</div>
</td>
<!--================= end Group Logo ==================-->
<!--================= start Project Logo ==================--><td width="50%" align="right">
<div align="right" class="projectLogo">
<a href="http://poi.apache.org/"><img border="0" class="logoImage" alt="POI" src="resources/images/project-logo.jpg"></a>
</div>
</td>
<!--================= end Project Logo ==================-->
</tr>
</tbody>
</table>
</div>
<!--================= end Banner ==================-->
<!--================= start Main ==================-->
<table width="100%" cellpadding="0" cellspacing="0" border="0" summary="nav" id="breadcrumbs">
<tbody>
<!--================= start Status ==================-->
<tr class="status">
<td>
<!--================= start BreadCrumb ==================--><a href="http://www.apache.org/">Apache</a> | <a href="http://poi.apache.org/">POI</a><a href=""></a>
<!--================= end BreadCrumb ==================--></td><td id="tabs">
<!--================= start Tabs ==================-->
<div class="tab">
<span class="selectedTab"><a class="base-selected" href="index.html">Home</a></span> | <script language="Javascript" type="text/javascript">
function printit() {  
if (window.print) {
    window.print() ;  
} else {
    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH="0" HEIGHT="0" CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
    WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";  
}
}
</script><script language="Javascript" type="text/javascript">
var NS = (navigator.appName == "Netscape");
var VERSION = parseInt(navigator.appVersion);
if (VERSION > 3) {
    document.write('  <a title="PRINT this page OUT" href="javascript:printit()">PRINT</a>');
}
</script>
</div>
<!--================= end Tabs ==================-->
</td>
</tr>
</tbody>
</table>
<!--================= end Status ==================-->
<table id="main" width="100%" cellpadding="8" cellspacing="0" summary="" border="0">
<tbody>
<tr valign="top">
<!--================= start Menu ==================-->
<td id="leftcol">
<div id="navcolumn">
<div class="menuBar">
<div class="menu">
<span class="menuLabel">Overview</span>
        
<div class="menuItem">
<a href="index.html">Home</a>
</div>
        
<div class="menuItem">
<a href="download.html">Download</a>
</div>
        
<div class="menuItem">
<a href="overview.html">Components</a>
</div>
        
<div class="menuItem">
<a href="text-extraction.html">Text Extraction</a>
</div>
        
<div class="menuItem">
<span class="menuSelected">Encryption support</span>
</div>
        
<div class="menuItem">
<a href="casestudies.html">Case Studies</a>
</div>
        
<div class="menuItem">
<a href="legal.html">Legal</a>
</div>
    
</div>
<div class="menu">
<span class="menuLabel">Help</span>
        
<div class="menuItem">
<a href="apidocs/index.html">Javadocs</a>
</div>
        
<div class="menuItem">
<a href="faq.html">FAQ</a>
</div>
        
<div class="menuItem">
<a href="mailinglists.html">Mailing Lists</a>
</div>
        
<div class="menuItem">
<a href="http://issues.apache.org/bugzilla/buglist.cgi?product=POI">Bug Database</a>
</div>
        
<div class="menuItem">
<a href="changes.html">Changes Log</a>
</div>
    
</div>
<div class="menu">
<span class="menuLabel">Getting Involved</span>
        
<div class="menuItem">
<a href="subversion.html">Subversion Repository</a>
</div>
        
<div class="menuItem">
<a href="howtobuild.html">How To Build</a>
</div>
        
<div class="menuItem">
<a href="guidelines.html">Contribution Guidelines</a>
</div>
        
<div class="menuItem">
<a href="who.html">Who We Are</a>
</div>
    
</div>
<div class="menu">
<span class="menuLabel">Component APIs</span>
        
<div class="menuItem">
<a href="spreadsheet/index.html">Excel (SS=HSSF+XSSF)</a>
</div>
        
<div class="menuItem">
<a href="hwpf/index.html">Word (HWPF+XWPF)</a>
</div>
        
<div class="menuItem">
<a href="slideshow/index.html">PowerPoint (HSLF+XSLF)</a>
</div>
        
<div class="menuItem">
<a href="oxml4j/index.html">OpenXML4J (OOXML)</a>
</div>
        
<div class="menuItem">
<a href="poifs/index.html">OLE2 Filesystem (POIFS)</a>
</div>
        
<div class="menuItem">
<a href="hpsf/index.html">OLE2 Document Props (HPSF)</a>
</div>
        
<div class="menuItem">
<a href="hsmf/index.html">Outlook (HSMF)</a>
</div>
        
<div class="menuItem">
<a href="hdgf/index.html">Visio (HDGF)</a>
</div>
        
<div class="menuItem">
<a href="hmef/index.html">TNEF (HMEF)</a>
</div>
        
<div class="menuItem">
<a href="hpbf/index.html">Publisher (HPBF)</a>
</div>
    
</div>
<div class="menu">
<span class="menuLabel">Apache Wide</span>
        
<div class="menuItem">
<a href="http://www.apache.org/">Apache Software Foundation</a>
</div>
        
<div class="menuItem">
<a href="http://www.apache.org/licenses/">License</a>
</div>
        
<div class="menuItem">
<a href="http://www.apache.org/foundation/sponsorship.html">Sponsorship</a>
</div>
        
<div class="menuItem">
<a href="http://www.apache.org/foundation/thanks.html">Thanks</a>
</div>
        
<div class="menuItem">
<a href="http://www.apache.org/security/">Security</a>
</div>
    
</div>
</div>
</div>
<form target="_blank" action="http://www.google.com/search" method="get">
<table summary="search" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img height="1" width="1" alt="" src="skin/images/spacer.gif" class="spacer"></td><td nowrap="nowrap">
                          Search Apache POI<br>
<input value="poi.apache.org" name="sitesearch" type="hidden"><input size="10" name="q" id="query" type="text"><img height="1" width="5" alt="" src="skin/images/spacer.gif" class="spacer"><input name="Search" value="GO" type="submit"></td><td><img height="1" width="1" alt="" src="skin/images/spacer.gif" class="spacer"></td>
</tr>
<tr>
<td colspan="3"><img height="7" width="1" alt="" src="skin/images/spacer.gif" class="spacer"></td>
</tr>
<tr>
<td class="bottom-left-thick"></td><td bgcolor="#a5b6c6"><img height="1" width="1" alt="" src="skin/images/spacer.gif" class="spacer"></td><td class="bottom-right-thick"></td>
</tr>
</table>
</form>
</td>
<!--================= end Menu ==================-->
<!--================= start Content ==================--><td>
<div id="bodycol">
<div class="app">
<div align="center">
<h1>Apache POI - Encryption support</h1>
</div>
<div class="h3">
  

   
    
<a name="Overview"></a>
<div class="h3">
<h3>Overview</h3>
</div>
	
<p>Apache POI contains support for reading few variants of encrypted office files: </p>
	
<ul>
		
<li>XLS - RC4 Encryption</li>
		
<li>XML-based formats (XLSX, DOCX and etc) - AES and Agile Encryption</li>
	
</ul>

	
<p>Some "write-protected" files are encrypted with build-in password, POI can read that files too.</p>
    	

    
<a name="XLS"></a>
<div class="h3">
<h3>XLS</h3>
</div>
    	
<p>When HSSF receive encrypted file, it tries to decode it with MSOffice build-in password. 
	Use static method setCurrentUserPassword(String password) of org.apache.poi.hssf.record.crypto.Biff8EncryptionKey to
	set password. It sets thread local variable. Do not forget to reset it to null after text extraction.
	</p>
    

    
<a name="XML-based+formats+-+Decryption"></a>
<div class="h3">
<h3>XML-based formats - Decryption</h3>
</div>
	
<p>XML-based formats are stored in OLE-package stream "EncryptedPackage". Use org.apache.poi.poifs.crypt.Decryptor
	to decode file:</p>

	
<pre class="code">
EncryptionInfo info = new EncryptionInfo(filesystem);
Decryptor d = Decryptor.getInstance(info);

try {
    if (!d.verifyPassword(password)) {
        throw new RuntimeException("Unable to process: document is encrypted");
    }

    InputStream dataStream = d.getDataStream(filesystem);

    // parse dataStream

} catch (GeneralSecurityException ex) {
    throw new RuntimeException("Unable to process encrypted document", ex);
}
	</pre>

	
<p>If you want to read file encrypted with build-in password, use Decryptor.DEFAULT_PASSWORD.</p>
     
     
     
<a name="XML-based+formats+-+Encryption"></a>
<div class="h3">
<h3>XML-based formats - Encryption</h3>
</div>
     
<p>Encrypting a file is similar to the above decryption process. Basically you'll need to choose between
     <a href="http://msdn.microsoft.com/en-us/library/dd952186(v=office.12).aspx">standard and agile encryption</a>.
     Apart of the CipherMode, the EncryptionInfo class provides further parameters to specify the cipher and
     hashing algorithm to be used.</p>
     
     
<pre class="code">
POIFSFileSystem fs = new POIFSFileSystem();
EncryptionInfo info = new EncryptionInfo(fs, EncryptionMode.agile);
// EncryptionInfo info = new EncryptionInfo(fs, EncryptionMode.agile, CipherAlgorithm.aes192, HashAlgorithm.sha384, -1, -1, null);

Encryptor enc = info.getEncryptor();
enc.confirmPassword("foobaa");

OPCPackage opc = OPCPackage.open(new File("..."), PackageAccess.READ_WRITE);
OutputStream os = enc.getDataStream(fs);
opc.save(os);
opc.close();

FileOutputStream fos = new FileOutputStream("...");
fs.writeFilesystem(fos);
fos.close();     
     </pre>
     
  

  

<div id="authors" align="right">by&nbsp;Maxim Valyanskiy</div>
</div>
</div>
</div>
</td>
<!--================= end Content ==================-->
</tr>
</tbody>
</table>
<!--================= end Main ==================-->
<!--================= start Footer ==================-->
<div id="footer">
<table summary="footer" cellspacing="0" cellpadding="4" width="100%" border="0">
<tbody>
<tr>
<!--================= start Copyright ==================-->
<td colspan="2">
<div align="center">
<div class="copyright">
              Copyright &copy; 2002-2012&nbsp;The Apache Software Foundation. All rights reserved.<br>
              Apache POI, POI, Apache, the Apache feather logo, and the Apache 
              POI project logo are trademarks of The Apache Software Foundation.
            </div>
</div>
</td>
<!--================= end Copyright ==================-->
</tr>
<tr>
<td align="left">
<!--================= start Host ==================-->
<!--================= end Host ==================--></td><td align="right">
<!--================= start Credits ==================-->
<div align="right">
<div class="credit"></div>
</div>
<!--================= end Credits ==================-->
</td>
</tr>
</tbody>
</table>
</div>
<!--================= end Footer ==================-->
</body>
</html>