Package org.pdfbox.exceptions

Examples of org.pdfbox.exceptions.CryptographyException


                    digest = md.digest();
                }
            }
            if( revision == 2 && length != 5 )
            {
                throw new CryptographyException(
                    "Error: Expected length=5 actual=" + length );
            }

            //3.3 STEP 4
            byte[] rc4Key = new byte[ (int)length ];
            System.arraycopy( digest, 0, rc4Key, 0, (int)length );

            //3.7 step 2
            if( revision == 2 )
            {
                rc4.setKey( rc4Key );
                rc4.write( o, result );
            }
            else if( revision == 3 || revision == 4)
            {
                /**
                byte[] iterationKey = new byte[ rc4Key.length ];
                byte[] dataToEncrypt = o;
                for( int i=19; i>=0; i-- )
                {
                    System.arraycopy( rc4Key, 0, iterationKey, 0, rc4Key.length );
                    for( int j=0; j< iterationKey.length; j++ )
                    {
                        iterationKey[j] = (byte)(iterationKey[j] ^ (byte)i);
                    }
                    rc4.setKey( iterationKey );
                    rc4.write( dataToEncrypt, result );
                    dataToEncrypt = result.toByteArray();
                    result.reset();
                }
                result.write( dataToEncrypt, 0, dataToEncrypt.length );
                */
                byte[] iterationKey = new byte[ rc4Key.length ];
               
             
                byte[] otemp = new byte[ o.length ]; //sm
                System.arraycopy( o, 0, otemp, 0, o.length ); //sm
                rc4.write( o, result);//sm
               
                for( int i=19; i>=0; i-- )
                {
                    System.arraycopy( rc4Key, 0, iterationKey, 0, rc4Key.length );
                    for( int j=0; j< iterationKey.length; j++ )
                    {
                        iterationKey[j] = (byte)(iterationKey[j] ^ (byte)i);
                    }
                    rc4.setKey( iterationKey );
                    result.reset()//sm
                    rc4.write( otemp, result ); //sm
                    otemp = result.toByteArray(); //sm               
                }
            }


            return result.toByteArray();

        }
        catch( NoSuchAlgorithmException e )
        {
            throw new CryptographyException( e );
        }
    }
View Full Code Here


                result.reset();
                result.write( finalResult );
            }
            catch( NoSuchAlgorithmException e )
            {
                throw new CryptographyException( e );
            }
        }
        return result.toByteArray();
    }
View Full Code Here

            }

            //step 7
            if( revision == 2 && length != 5 )
            {
                throw new CryptographyException(
                    "Error: length should be 5 when revision is two actual=" + length );
            }
            System.arraycopy( digest, 0, result, 0, length );
        }
        catch( NoSuchAlgorithmException e )
        {
            throw new CryptographyException( e );
        }
        return result;
    }
View Full Code Here

                    digest = md.digest();
                }
            }
            if( revision == 2 && length != 5 )
            {
                throw new CryptographyException(
                    "Error: Expected length=5 actual=" + length );
            }

            //STEP 4
            byte[] rc4Key = new byte[ length ];
            System.arraycopy( digest, 0, rc4Key, 0, length );

            //STEP 5
            byte[] paddedUser = truncateOrPad( userPassword );


            //STEP 6
            rc4.setKey( rc4Key );
            ByteArrayOutputStream crypted = new ByteArrayOutputStream();
            rc4.write( new ByteArrayInputStream( paddedUser ), crypted );


            //STEP 7
            if( revision == 3 || revision == 4 )
            {
                byte[] iterationKey = new byte[ rc4Key.length ];
                for( int i=1; i<20; i++ )
                {
                    System.arraycopy( rc4Key, 0, iterationKey, 0, rc4Key.length );
                    for( int j=0; j< iterationKey.length; j++ )
                    {
                        iterationKey[j] = (byte)(iterationKey[j] ^ (byte)i);
                    }
                    rc4.setKey( iterationKey );
                    ByteArrayInputStream input = new ByteArrayInputStream( crypted.toByteArray() );
                    crypted.reset();
                    rc4.write( input, crypted );
                }
            }

            //STEP 8
            return crypted.toByteArray();
        }
        catch( NoSuchAlgorithmException e )
        {
            throw new CryptographyException( e.getMessage() );
        }
    }
View Full Code Here

                idArray.add( idString );
                document.setDocumentID( idArray );
            }
            catch( NoSuchAlgorithmException e )
            {
                throw new CryptographyException( e );
            }

        }
        COSString id = (COSString)idArray.getObject( 0 );
        encryption = new PDFEncryption();
View Full Code Here

            this.openProtection(m);       
            document.dereferenceObjectStreams();
        }
        catch(BadSecurityHandlerException e)
        {
            throw new CryptographyException(e);
        }
    }
View Full Code Here

                new StandardProtectionPolicy(ownerPassword, userPassword, new AccessPermission());
            this.protect(policy);
        }
        catch(BadSecurityHandlerException e)
        {
            throw new CryptographyException(e);
        }               
    }
View Full Code Here

            MessageDigest md = MessageDigest.getInstance( "MD5" );
            digestedKey = md.digest( newKey );
        }
        catch( NoSuchAlgorithmException e )
        {
            throw new CryptographyException( e );
        }

        //step 4
        int length = Math.min( newKey.length, 16 );
        byte[] finalKey = new byte[ length ];
View Full Code Here

                    digest = md.digest();
                }
            }
            if( revision == 2 && length != 5 )
            {
                throw new CryptographyException(
                    "Error: Expected length=5 actual=" + length );
            }

            //3.3 STEP 4
            byte[] rc4Key = new byte[ (int)length ];
            System.arraycopy( digest, 0, rc4Key, 0, (int)length );

            //3.7 step 2
            if( revision == 2 )
            {
                rc4.setKey( rc4Key );
                rc4.write( o, result );
            }
            else if( revision == 3 )
            {
                byte[] iterationKey = new byte[ rc4Key.length ];
                byte[] dataToEncrypt = o;
                for( int i=19; i>=0; i-- )
                {
                    System.arraycopy( rc4Key, 0, iterationKey, 0, rc4Key.length );
                    for( int j=0; j< iterationKey.length; j++ )
                    {
                        iterationKey[j] = (byte)(iterationKey[j] ^ (byte)i);
                    }
                    rc4.setKey( iterationKey );
                    rc4.write( dataToEncrypt, result );
                    dataToEncrypt = result.toByteArray();
                    result.reset();
                }
                result.write( dataToEncrypt, 0, dataToEncrypt.length );
            }


            return result.toByteArray();

        }
        catch( NoSuchAlgorithmException e )
        {
            throw new CryptographyException( e );
        }
    }
View Full Code Here

                result.reset();
                result.write( finalResult );
            }
            catch( NoSuchAlgorithmException e )
            {
                throw new CryptographyException( e );
            }
        }
        return result.toByteArray();
    }
View Full Code Here

TOP

Related Classes of org.pdfbox.exceptions.CryptographyException

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.