Java Code Examples for org.apache.pdfbox.cos.COSString#getBytes()
The following examples show how to use
org.apache.pdfbox.cos.COSString#getBytes() .
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: SecurityHandler.java From gcs with Mozilla Public License 2.0 | 6 votes |
/** * This will decrypt a string. * * @param string the string to decrypt. * @param objNum The object number. * @param genNum The object generation number. * * @throws IOException If an error occurs writing the new string. */ private void decryptString(COSString string, long objNum, long genNum) throws IOException { // String encrypted with identity filter if (COSName.IDENTITY.equals(stringFilterName)) { return; } ByteArrayInputStream data = new ByteArrayInputStream(string.getBytes()); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { encryptData(objNum, genNum, data, outputStream, true /* decrypt */); string.setValue(outputStream.toByteArray()); } catch (IOException ex) { LOG.error("Failed to decrypt COSString of length " + string.getBytes().length + " in object " + objNum + ": " + ex.getMessage()); } }
Example 2
Source File: StandardSecurityHandler.java From gcs with Mozilla Public License 2.0 | 6 votes |
private byte[] getDocumentIDBytes(COSArray documentIDArray) { //some documents may not have document id, see //test\encryption\encrypted_doc_no_id.pdf byte[] documentIDBytes; if( documentIDArray != null && documentIDArray.size() >= 1 ) { COSString id = (COSString)documentIDArray.getObject( 0 ); documentIDBytes = id.getBytes(); } else { documentIDBytes = new byte[0]; } return documentIDBytes; }
Example 3
Source File: PDEncryption.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * This will get the O entry in the standard encryption dictionary. * * @return A 32 byte array or null if there is no owner key. * * @throws IOException If there is an error accessing the data. */ public byte[] getOwnerKey() throws IOException { byte[] o = null; COSString owner = (COSString) dictionary.getDictionaryObject( COSName.O ); if( owner != null ) { o = owner.getBytes(); } return o; }
Example 4
Source File: PDEncryption.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * This will get the U entry in the standard encryption dictionary. * * @return A 32 byte array or null if there is no user key. * * @throws IOException If there is an error accessing the data. */ public byte[] getUserKey() throws IOException { byte[] u = null; COSString user = (COSString) dictionary.getDictionaryObject( COSName.U ); if( user != null ) { u = user.getBytes(); } return u; }
Example 5
Source File: PDEncryption.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * This will get the OE entry in the standard encryption dictionary. * * @return A 32 byte array or null if there is no owner encryption key. * * @throws IOException If there is an error accessing the data. */ public byte[] getOwnerEncryptionKey() throws IOException { byte[] oe = null; COSString ownerEncryptionKey = (COSString)dictionary.getDictionaryObject( COSName.OE ); if( ownerEncryptionKey != null ) { oe = ownerEncryptionKey.getBytes(); } return oe; }
Example 6
Source File: PDEncryption.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * This will get the UE entry in the standard encryption dictionary. * * @return A 32 byte array or null if there is no user encryption key. * * @throws IOException If there is an error accessing the data. */ public byte[] getUserEncryptionKey() throws IOException { byte[] ue = null; COSString userEncryptionKey = (COSString)dictionary.getDictionaryObject( COSName.UE ); if( userEncryptionKey != null ) { ue = userEncryptionKey.getBytes(); } return ue; }
Example 7
Source File: PDEncryption.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * Get the Perms entry in the encryption dictionary. * * @return A 16 byte array or null if there is no Perms entry. * * @throws IOException If there is an error accessing the data. */ public byte[] getPerms() throws IOException { byte[] perms = null; COSString permsCosString = (COSString)dictionary.getDictionaryObject( COSName.PERMS ); if( permsCosString != null ) { perms = permsCosString.getBytes(); } return perms; }
Example 8
Source File: PDFontDescriptor.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * Returns the Panose entry of the Style dictionary, if any. * * @return A Panose wrapper object. */ public PDPanose getPanose() { COSDictionary style = (COSDictionary)dic.getDictionaryObject(COSName.STYLE); if (style != null) { COSString panose = (COSString)style.getDictionaryObject(COSName.PANOSE); byte[] bytes = panose.getBytes(); return new PDPanose(bytes); } return null; }
Example 9
Source File: SecurityHandler.java From gcs with Mozilla Public License 2.0 | 3 votes |
/** * This will encrypt a string. * * @param string the string to encrypt. * @param objNum The object number. * @param genNum The object generation number. * * @throws IOException If an error occurs writing the new string. */ public void encryptString(COSString string, long objNum, int genNum) throws IOException { ByteArrayInputStream data = new ByteArrayInputStream(string.getBytes()); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); encryptData(objNum, genNum, data, buffer, false /* encrypt */); string.setValue(buffer.toByteArray()); }