Java Code Examples for org.apache.pdfbox.cos.COSString#getBytes()

The following examples show how to use org.apache.pdfbox.cos.COSString#getBytes() . These examples are extracted from open source projects. 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 Project: gcs   File: SecurityHandler.java    License: Mozilla Public License 2.0 6 votes vote down vote up
/**
 * 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
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 Project: gcs   File: PDEncryption.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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 Project: gcs   File: PDEncryption.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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 Project: gcs   File: PDEncryption.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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 Project: gcs   File: PDEncryption.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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 Project: gcs   File: PDEncryption.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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 Project: gcs   File: PDFontDescriptor.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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 Project: gcs   File: SecurityHandler.java    License: Mozilla Public License 2.0 3 votes vote down vote up
/**
 * 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());
}