Class RC4Cipher

java.lang.Object
org.apache.pdfbox.pdmodel.encryption.RC4Cipher

class RC4Cipher extends Object
An implementation of the RC4 stream cipher.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private int
     
    private int
     
    private final int[]
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    private int
    encrypt(byte aByte)
     
    private static int
    fixByte(byte aByte)
    This will ensure that the value for a byte >=0.
    void
    setKey(byte[] key)
    This will reset the key to be used.
    private static void
    swap(int[] data, int firstIndex, int secondIndex)
    This will swap two values in an array.
    void
    write(byte[] data, int offset, int len, OutputStream output)
    Deprecated.
    This method will be removed in 4.0.
    private void
    write(byte[] data, int offset, int len, OutputStream output, byte[] buffer)
    This will encrypt and write the data.
    void
    write(byte[] data, OutputStream output)
    This will encrypt and write the data.
    void
    write(byte aByte, OutputStream output)
    Deprecated.
    This method will be removed in 4.0.
    void
    This will encrypt and write the data.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • salt

      private final int[] salt
    • b

      private int b
    • c

      private int c
  • Constructor Details

    • RC4Cipher

      RC4Cipher()
      Constructor.
  • Method Details

    • setKey

      public void setKey(byte[] key)
      This will reset the key to be used.
      Parameters:
      key - The RC4 key used during encryption.
    • fixByte

      private static int fixByte(byte aByte)
      This will ensure that the value for a byte >=0.
      Parameters:
      aByte - The byte to test against.
      Returns:
      A value >=0 and < 256
    • swap

      private static void swap(int[] data, int firstIndex, int secondIndex)
      This will swap two values in an array.
      Parameters:
      data - The array to swap from.
      firstIndex - The index of the first element to swap.
      secondIndex - The index of the second element to swap.
    • encrypt

      private int encrypt(byte aByte)
    • write

      @Deprecated public void write(byte aByte, OutputStream output) throws IOException
      Deprecated.
      This method will be removed in 4.0.
      This will encrypt and write the next byte.
      Parameters:
      aByte - The byte to encrypt.
      output - The stream to write to.
      Throws:
      IOException - If there is an error writing to the output stream.
    • write

      public void write(byte[] data, OutputStream output) throws IOException
      This will encrypt and write the data.
      Parameters:
      data - The data to encrypt.
      output - The stream to write to.
      Throws:
      IOException - If there is an error writing to the output stream.
    • write

      public void write(InputStream data, OutputStream output) throws IOException
      This will encrypt and write the data.
      Parameters:
      data - The data to encrypt.
      output - The stream to write to.
      Throws:
      IOException - If there is an error writing to the output stream.
    • write

      @Deprecated public void write(byte[] data, int offset, int len, OutputStream output) throws IOException
      Deprecated.
      This method will be removed in 4.0.
      This will encrypt and write the data.
      Parameters:
      data - The data to encrypt.
      offset - The offset into the array to start reading data from.
      len - The number of bytes to attempt to read.
      output - The stream to write to.
      Throws:
      IOException - If there is an error writing to the output stream.
    • write

      private void write(byte[] data, int offset, int len, OutputStream output, byte[] buffer) throws IOException
      This will encrypt and write the data.
      Parameters:
      data - The data to encrypt, may be overwritten.
      offset - The offset into the array to start reading data from.
      len - The number of bytes to attempt to read.
      output - The stream to write to.
      buffer - The buffer to use, it can be altered and be identical to the data to encrypt.
      Throws:
      IOException - If there is an error writing to the output stream.