當前位置: 首頁>>代碼示例>>Java>>正文


Java Biff8EncryptionKey類代碼示例

本文整理匯總了Java中org.apache.poi.hssf.record.crypto.Biff8EncryptionKey的典型用法代碼示例。如果您正苦於以下問題:Java Biff8EncryptionKey類的具體用法?Java Biff8EncryptionKey怎麽用?Java Biff8EncryptionKey使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Biff8EncryptionKey類屬於org.apache.poi.hssf.record.crypto包,在下文中一共展示了Biff8EncryptionKey類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: importTables

import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; //導入依賴的package包/類
/**
 * core code
 *
 * @param stream   asset stream or file stream
 * @param fileName origin file name
 * @throws Exception
 */
private boolean importTables(InputStream stream, String fileName) throws Exception {
    Workbook workbook;
    if (fileName.toLowerCase().endsWith(".xls")) {
        if (!TextUtils.isEmpty(decryptKey)) {
            Biff8EncryptionKey.setCurrentUserPassword("1234567");
        }
        workbook = new HSSFWorkbook(stream);
    } else {
        throw new UnsupportedOperationException("Unsupported file format!");
    }
    stream.close();
    int sheetNumber = workbook.getNumberOfSheets();
    for (int i = 0; i < sheetNumber; i++) {
        createTable(workbook.getSheetAt(i));
    }
    database.close();
    return true;
}
 
開發者ID:li-yu,項目名稱:SQLiteToExcel,代碼行數:26,代碼來源:ExcelToSQLite.java

示例2: decrypt

import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; //導入依賴的package包/類
/**
    * 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.
    * 
    * (http://poi.apache.org/encryption.html)
    * 
    * @param input
    * @param password
    * @return
    * @throws IOException
    */
   public static HSSFWorkbook decrypt(InputStream input, String password)
    throws IOException {

try {

    Biff8EncryptionKey.setCurrentUserPassword(password);

    return new HSSFWorkbook(input);

} catch (Exception ex) {
    throw new RuntimeException("Unable to process encrypted document",
	    ex);
} finally {
    Biff8EncryptionKey.setCurrentUserPassword(null);
}

   }
 
開發者ID:utluiz,項目名稱:poi-security,代碼行數:32,代碼來源:XlsDecryptor.java

示例3: finalizeWriteEncryptedHSSF

import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; //導入依賴的package包/類
private void finalizeWriteEncryptedHSSF() throws IOException {
	LOG.debug("encrypting HSSFWorkbook");
	Biff8EncryptionKey.setCurrentUserPassword(this.howc.getPassword());
	try {
		this.currentWorkbook.write(this.oStream);
	} finally {
		Biff8EncryptionKey.setCurrentUserPassword(null);
		if (this.oStream!=null) {
			this.oStream.close();
		}
	}
}
 
開發者ID:ZuInnoTe,項目名稱:hadoopoffice,代碼行數:13,代碼來源:MSExcelWriter.java

示例4: EncryptFile

import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; //導入依賴的package包/類
/**
 * Encrypt a file, support .xls file only
 *
 * @param file
 * @param encryptKey
 * @throws Exception
 */
public static void EncryptFile(File file, String encryptKey) throws Exception {
    FileInputStream fileInput = new FileInputStream(file.getPath());
    BufferedInputStream bufferInput = new BufferedInputStream(fileInput);
    POIFSFileSystem poiFileSystem = new POIFSFileSystem(bufferInput);
    Biff8EncryptionKey.setCurrentUserPassword(encryptKey);
    HSSFWorkbook workbook = new HSSFWorkbook(poiFileSystem, true);
    FileOutputStream fileOut = new FileOutputStream(file.getPath());
    workbook.writeProtectWorkbook(Biff8EncryptionKey.getCurrentUserPassword(), "");
    workbook.write(fileOut);
    bufferInput.close();
    fileOut.close();
}
 
開發者ID:li-yu,項目名稱:SQLiteToExcel,代碼行數:20,代碼來源:SecurityUtil.java


注:本文中的org.apache.poi.hssf.record.crypto.Biff8EncryptionKey類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。