Top Description Fields Constructors Methods
org.apache.pdfbox.pdmodel.encryption

pack-priv Class RC4Cipher

extends Object
Class Inheritance
Imports
java.io.IOException, .InputStream, .OutputStream

An implementation of the RC4 stream cipher.
Author
Ben Litchfield

Field Summary

Modifier and TypeField and Description
private int
b

private int
c

private final int[]

Constructor Summary

AccessConstructor and Description
pack-priv
RC4Cipher()

Constructor.

Method Summary

Modifier and TypeMethod and Description
private static int

Returns:

A value >=0 and < 256
fixByte
(byte
The byte to test against.
aByte
)

This will ensure that the value for a byte >=0.

public void
setKey(byte[]
The RC4 key used during encryption.
key
)

This will reset the key to be used.

private static void
swap(int[]
The array to swap from.
data
,
int
The index of the first element to swap.
firstIndex
,
int
The index of the second element to swap.
secondIndex
)

This will swap two values in an array.

public void
write(byte
The byte to encrypt.
aByte
,
OutputStream
The stream to write to.
output
)

This will encrypt and write the next byte.

public void
write(byte[]
The data to encrypt.
data
,
OutputStream
The stream to write to.
output
)

This will encrypt and write the data.

public void
write(InputStream
The data to encrypt.
data
,
OutputStream
The stream to write to.
output
)

This will encrypt and write the data.

public void
write(byte[]
The data to encrypt.
data
,
int
The offset into the array to start reading data from.
offset
,
int
The number of bytes to attempt to read.
len
,
OutputStream
The stream to write to.
output
)

This will encrypt and write the data.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bback to summary
private int b
cback to summary
private int c
saltback to summary
private final int[] salt

Constructor Detail

RC4Cipherback to summary
pack-priv RC4Cipher()

Constructor.

Method Detail

fixByteback to summary
private static int fixByte(byte aByte)

This will ensure that the value for a byte >=0.

Parameters
aByte:byte

The byte to test against.

Returns:int

A value >=0 and < 256

setKeyback to summary
public void setKey(byte[] key)

This will reset the key to be used.

Parameters
key:byte[]

The RC4 key used during encryption.

swapback to summary
private static void swap(int[] data, int firstIndex, int secondIndex)

This will swap two values in an array.

Parameters
data:int[]

The array to swap from.

firstIndex:int

The index of the first element to swap.

secondIndex:int

The index of the second element to swap.

writeback to summary
public void write(byte aByte, OutputStream output) throws IOException

This will encrypt and write the next byte.

Parameters
aByte:byte

The byte to encrypt.

output:OutputStream

The stream to write to.

Exceptions
IOException:
If there is an error writing to the output stream.
writeback to summary
public void write(byte[] data, OutputStream output) throws IOException

This will encrypt and write the data.

Parameters
data:byte[]

The data to encrypt.

output:OutputStream

The stream to write to.

Exceptions
IOException:
If there is an error writing to the output stream.
writeback to summary
public void write(InputStream data, OutputStream output) throws IOException

This will encrypt and write the data.

Parameters
data:InputStream

The data to encrypt.

output:OutputStream

The stream to write to.

Exceptions
IOException:
If there is an error writing to the output stream.
writeback to summary
public void write(byte[] data, int offset, int len, OutputStream output) throws IOException

This will encrypt and write the data.

Parameters
data:byte[]

The data to encrypt.

offset:int

The offset into the array to start reading data from.

len:int

The number of bytes to attempt to read.

output:OutputStream

The stream to write to.

Exceptions
IOException:
If there is an error writing to the output stream.