Package org.pdfbox.exceptions

Examples of org.pdfbox.exceptions.CryptographyException


            }

            //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, (int)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[ (int)length ];
            System.arraycopy( digest, 0, rc4Key, 0, (int)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 )
            {
                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

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.