Java Code Examples for org.apache.poi.poifs.crypt.EncryptionInfo#getVerifier()
The following examples show how to use
org.apache.poi.poifs.crypt.EncryptionInfo#getVerifier() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BinaryRC4Encryptor.java From lams with GNU General Public License v2.0 | 6 votes |
protected void createEncryptionInfoEntry(DirectoryNode dir) throws IOException { DataSpaceMapUtils.addDefaultDataSpace(dir); final EncryptionInfo info = getEncryptionInfo(); final BinaryRC4EncryptionHeader header = (BinaryRC4EncryptionHeader)info.getHeader(); final BinaryRC4EncryptionVerifier verifier = (BinaryRC4EncryptionVerifier)info.getVerifier(); EncryptionRecord er = new EncryptionRecord() { @Override public void write(LittleEndianByteArrayOutputStream bos) { bos.writeShort(info.getVersionMajor()); bos.writeShort(info.getVersionMinor()); header.write(bos); verifier.write(bos); } }; DataSpaceMapUtils.createEncryptionEntry(dir, "EncryptionInfo", er); }
Example 2
Source File: StandardEncryptor.java From lams with GNU General Public License v2.0 | 6 votes |
protected void createEncryptionInfoEntry(DirectoryNode dir) throws IOException { final EncryptionInfo info = getEncryptionInfo(); final StandardEncryptionHeader header = (StandardEncryptionHeader)info.getHeader(); final StandardEncryptionVerifier verifier = (StandardEncryptionVerifier)info.getVerifier(); EncryptionRecord er = new EncryptionRecord(){ @Override public void write(LittleEndianByteArrayOutputStream bos) { bos.writeShort(info.getVersionMajor()); bos.writeShort(info.getVersionMinor()); bos.writeInt(info.getEncryptionFlags()); header.write(bos); verifier.write(bos); } }; createEncryptionEntry(dir, "EncryptionInfo", er); // TODO: any properties??? }
Example 3
Source File: CryptoAPIDecryptor.java From lams with GNU General Public License v2.0 | 6 votes |
protected static Cipher initCipherForBlock(Cipher cipher, int block, EncryptionInfo encryptionInfo, SecretKey skey, int encryptMode) throws GeneralSecurityException { EncryptionVerifier ver = encryptionInfo.getVerifier(); HashAlgorithm hashAlgo = ver.getHashAlgorithm(); byte blockKey[] = new byte[4]; LittleEndian.putUInt(blockKey, 0, block); MessageDigest hashAlg = CryptoFunctions.getMessageDigest(hashAlgo); hashAlg.update(skey.getEncoded()); byte encKey[] = hashAlg.digest(blockKey); EncryptionHeader header = encryptionInfo.getHeader(); int keyBits = header.getKeySize(); encKey = CryptoFunctions.getBlock0(encKey, keyBits / 8); if (keyBits == 40) { encKey = CryptoFunctions.getBlock0(encKey, 16); } SecretKey key = new SecretKeySpec(encKey, skey.getAlgorithm()); if (cipher == null) { cipher = CryptoFunctions.getCipher(key, header.getCipherAlgorithm(), null, null, encryptMode); } else { cipher.init(encryptMode, key); } return cipher; }
Example 4
Source File: HSSFWorkbook.java From lams with GNU General Public License v2.0 | 5 votes |
private void updateEncryptionInfo() { // make sure, that we've read all the streams ... readProperties(); FilePassRecord fpr = (FilePassRecord)workbook.findFirstRecordBySid(FilePassRecord.sid); String password = Biff8EncryptionKey.getCurrentUserPassword(); WorkbookRecordList wrl = workbook.getWorkbookRecordList(); if (password == null) { if (fpr != null) { // need to remove password data wrl.remove(fpr); } } else { // create password record if (fpr == null) { fpr = new FilePassRecord(EncryptionMode.cryptoAPI); wrl.add(1, fpr); } // check if the password has been changed EncryptionInfo ei = fpr.getEncryptionInfo(); EncryptionVerifier ver = ei.getVerifier(); byte encVer[] = ver.getEncryptedVerifier(); Decryptor dec = ei.getDecryptor(); Encryptor enc = ei.getEncryptor(); try { if (encVer == null || !dec.verifyPassword(password)) { enc.confirmPassword(password); } else { byte verifier[] = dec.getVerifier(); byte salt[] = ver.getSalt(); enc.confirmPassword(password, null, null, verifier, salt, null); } } catch (GeneralSecurityException e) { throw new EncryptedDocumentException("can't validate/update encryption setting", e); } } }