Package org.pdfbox.cos

Examples of org.pdfbox.cos.COSString


       
        int dicPermissions = dictionary.getPermissions();
        int dicRevision = dictionary.getRevision();
        int dicLength = dictionary.getLength()/8;

        COSString id = (COSString)document.getDocument().getDocumentID().getObject( 0 );
        byte[] u = dictionary.getUserKey();
        byte[] o = dictionary.getOwnerKey();

        boolean isUserPassword =
            isUserPassword(
                password.getBytes(),
                u,
                o,
                dicPermissions,
                id.getBytes(),
                dicRevision,
                dicLength );
        boolean isOwnerPassword =
            isOwnerPassword(
                password.getBytes(),
                u,
                o,
                dicPermissions,
                id.getBytes(),
                dicRevision,
                dicLength );

        if( isUserPassword )
        {
            encryptionKey =
                computeEncryptedKey(
                    password.getBytes(),
                    o,
                    dicPermissions,
                    id.getBytes(),
                    dicRevision,
                    dicLength );
        }
        else if( isOwnerPassword )
        {
            byte[] computedUserPassword = getUserPassword(password.getBytes(),o,dicRevision,dicLength );
            encryptionKey =
                computeEncryptedKey(
                    computedUserPassword,
                    o,
                    dicPermissions,
                    id.getBytes(),
                    dicRevision,
                    dicLength );
        }
        else
        {
View Full Code Here


                md.update( time.toByteArray() );
                md.update( ownerPassword.getBytes() );
                md.update( userPassword.getBytes() );
                md.update( document.getDocument().toString().getBytes() );
                byte[] id = md.digest( this.toString().getBytes() );
                COSString idString = new COSString();
                idString.append( id );
                idArray.add( idString );
                idArray.add( idString );
                document.getDocument().setDocumentID( idArray );
            }
            catch( NoSuchAlgorithmException e )
            {
                throw new CryptographyException( e );
            }
            catch(IOException e )
            {
                throw new CryptographyException( e );
            }
        }
       
        COSString id = (COSString)idArray.getObject( 0 );       
       
        byte[] o = computeOwnerPassword(
            ownerPassword.getBytes("ISO-8859-1"),
            userPassword.getBytes("ISO-8859-1"), revision, length);

        byte[] u = computeUserPassword(
            userPassword.getBytes("ISO-8859-1"),
            o, permissionInt, id.getBytes(), revision, length);

        encryptionKey = computeEncryptedKey(
            userPassword.getBytes("ISO-8859-1"), o, permissionInt, id.getBytes(), revision, length);

        encryptionDictionary.setOwnerKey(o);
        encryptionDictionary.setUserKey(u);       
       
        document.setEncryptionDictionary( encryptionDictionary );
View Full Code Here

            for (int i = 0; i < fields.size() && retval == null; i++)
            {
                COSDictionary element = (COSDictionary) fields.getObject(i);
                if( element != null )
                {
                    COSString fieldName =
                        (COSString)element.getDictionaryObject( COSName.getPDFName( "T" ) );
                    if( fieldName.getString().equals( name ) ||
                        fieldName.getString().equals( nameSubSection[0] ) )
                    {
                        PDField root = PDFieldFactory.createField( this, element );
                       
                        if( nameSubSection.length > 1 )
                        {
View Full Code Here

     * @return A 32 byte array or null if there is no owner key.
     */
    public byte[] getOwnerKey()
    {
       byte[] o = null;
       COSString owner = (COSString)encryptionDictionary.getDictionaryObject( COSName.getPDFName( "O" ) );
       if( owner != null )
       {
           o = owner.getBytes();
       }
       return o;
    }
View Full Code Here

     *
     * @throws IOException If there is an error setting the data.
     */
    public void setOwnerKey( byte[] o ) throws IOException
    {
       COSString owner = new COSString();
       owner.append( o );
       encryptionDictionary.setItem( COSName.getPDFName( "O" ), owner );
    }
View Full Code Here

     * @return A 32 byte array or null if there is no user key.
     */
    public byte[] getUserKey()
    {
       byte[] u = null;
       COSString user = (COSString)encryptionDictionary.getDictionaryObject( COSName.getPDFName( "U" ) );
       if( user != null )
       {
           u = user.getBytes();
       }
       return u;
    }
View Full Code Here

     *
     * @throws IOException If there is an error setting the data.
     */
    public void setUserKey( byte[] u ) throws IOException
    {
       COSString user = new COSString();
       user.append( u );
       encryptionDictionary.setItem( COSName.getPDFName( "U" ), user );
    }
View Full Code Here

     *
     * @throws IOException If there is an error setting the data.
     */
    public void setOwnerKey(byte[] o) throws IOException
    {
        COSString owner = new COSString();
        owner.append( o );
        encryptionDictionary.setItem( COSName.getPDFName( "O" ), owner );
    }
View Full Code Here

     * @throws IOException If there is an error accessing the data.
     */
    public byte[] getOwnerKey() throws IOException
    {
        byte[] o = null;
        COSString owner = (COSString)encryptionDictionary.getDictionaryObject( COSName.getPDFName( "O" ) );
        if( owner != null )
        {
            o = owner.getBytes();
        }
        return o;
    }
View Full Code Here

     *
     * @throws IOException If there is an error setting the data.
     */
    public void setUserKey(byte[] u) throws IOException
    {
        COSString user = new COSString();
        user.append( u );
        encryptionDictionary.setItem( COSName.getPDFName( "U" ), user );
    }
View Full Code Here

TOP

Related Classes of org.pdfbox.cos.COSString

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.