Class RC4Cipher
java.lang.Object
org.apache.pdfbox.pdmodel.encryption.RC4Cipher
An implementation of the RC4 stream cipher.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static intfixByte(byte aByte) This will ensure that the value for a byte >=0.voidsetKey(byte[] key) This will reset the key to be used.private static voidswap(int[] data, int firstIndex, int secondIndex) This will swap two values in an array.voidwrite(byte[] data, int offset, int len, OutputStream output) This will encrypt and write the data.voidwrite(byte[] data, OutputStream output) This will encrypt and write the data.voidwrite(byte aByte, OutputStream output) This will encrypt and write the next byte.voidwrite(InputStream data, OutputStream output) This will encrypt and write the data.
-
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.
-
write
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
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
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
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.
-