/** * This will reset the key to be used. * * @param key The RC4 key used during encryption. */ public void setKey( byte[] key ) { b = 0; c = 0; if(key.length < 1 || key.length > 32) { throw new IllegalArgumentException("number of bytes must be between 1 and 32"); } for(int i = 0; i < salt.length; i++) { salt[i] = i; } int keyIndex = 0; int saltIndex = 0; for( int i = 0; i < salt.length; i++) { saltIndex = (fixByte(key[keyIndex]) + salt[i] + saltIndex) % 256; swap( salt, i, saltIndex ); keyIndex = (keyIndex + 1) % key.length; } }
/** * Encrypt or decrypt data with RC4. * * @param finalKey The final key obtained with via {@link #calcFinalKey(long, long)}. * @param input The data to encrypt. * @param output The output to write the encrypted data to. * * @throws IOException If there is an error reading the data. */ protected void encryptDataRC4(byte[] finalKey, byte[] input, OutputStream output) throws IOException { rc4.setKey(finalKey); rc4.write(input, output); }
/** * This will encrypt and write the data. * * @param data The data to encrypt. * @param output The stream to write to. * * @throws IOException If there is an error writing to the output stream. */ public void write( byte[] data, OutputStream output ) throws IOException { for (byte aData : data) { write(aData, output); } }
/** * This will encrypt and write the next byte. * * @param aByte The byte to encrypt. * @param output The stream to write to. * * @throws IOException If there is an error writing to the output stream. */ public void write( byte aByte, OutputStream output ) throws IOException { b = (b + 1) % 256; c = (salt[b] + c) % 256; swap( salt, b, c ); int saltIndex = (salt[b] + salt[c]) % 256; output.write(aByte ^ (byte)salt[saltIndex]); }
/** * This will encrypt and write the data. * * @param data The data to encrypt. * @param offset The offset into the array to start reading data from. * @param len The number of bytes to attempt to read. * @param output The stream to write to. * * @throws IOException If there is an error writing to the output stream. */ public void write( byte[] data, int offset, int len, OutputStream output) throws IOException { for( int i = offset; i < offset + len; i++ ) { write( data[i], output ); } } }
/** * This will encrypt and write the next byte. * * @param aByte The byte to encrypt. * @param output The stream to write to. * * @throws IOException If there is an error writing to the output stream. */ public void write( byte aByte, OutputStream output ) throws IOException { b = (b + 1) % 256; c = (salt[b] + c) % 256; swap( salt, b, c ); int saltIndex = (salt[b] + salt[c]) % 256; output.write(aByte ^ (byte)salt[saltIndex]); }
/** * Encrypt or decrypt data with RC4. * * @param finalKey The final key obtained with via {@link #calcFinalKey(long, long)}. * @param input The data to encrypt. * @param output The output to write the encrypted data to. * * @throws IOException If there is an error reading the data. */ protected void encryptDataRC4(byte[] finalKey, InputStream input, OutputStream output) throws IOException { rc4.setKey(finalKey); rc4.write(input, output); }
/** * This will reset the key to be used. * * @param key The RC4 key used during encryption. */ public void setKey( byte[] key ) { b = 0; c = 0; if(key.length < 1 || key.length > 32) { throw new IllegalArgumentException("number of bytes must be between 1 and 32"); } for(int i = 0; i < salt.length; i++) { salt[i] = i; } int keyIndex = 0; int saltIndex = 0; for( int i = 0; i < salt.length; i++) { saltIndex = (fixByte(key[keyIndex]) + salt[i] + saltIndex) % 256; swap( salt, i, saltIndex ); keyIndex = (keyIndex + 1) % key.length; } }
/** * This will encrypt and write the data. * * @param data The data to encrypt. * @param output The stream to write to. * * @throws IOException If there is an error writing to the output stream. */ public void write( InputStream data, OutputStream output ) throws IOException { byte[] buffer = new byte[1024]; int amountRead; while( (amountRead = data.read( buffer )) != -1 ) { write( buffer, 0, amountRead, output ); } }
/** * This will encrypt and write the next byte. * * @param aByte The byte to encrypt. * @param output The stream to write to. * * @throws IOException If there is an error writing to the output stream. */ public void write( byte aByte, OutputStream output ) throws IOException { b = (b + 1) % 256; c = (salt[b] + c) % 256; swap( salt, b, c ); int saltIndex = (salt[b] + salt[c]) % 256; output.write(aByte ^ (byte)salt[saltIndex]); }
/** * Encrypt or decrypt data with RC4. * * @param finalKey The final key obtained with via {@link #calcFinalKey(long, long)}. * @param input The data to encrypt. * @param output The output to write the encrypted data to. * * @throws IOException If there is an error reading the data. */ protected void encryptDataRC4(byte[] finalKey, byte[] input, OutputStream output) throws IOException { rc4.setKey(finalKey); rc4.write(input, output); }
/** * This will reset the key to be used. * * @param key The RC4 key used during encryption. */ public void setKey( byte[] key ) { b = 0; c = 0; if(key.length < 1 || key.length > 32) { throw new IllegalArgumentException("number of bytes must be between 1 and 32"); } for(int i = 0; i < salt.length; i++) { salt[i] = i; } int keyIndex = 0; int saltIndex = 0; for( int i = 0; i < salt.length; i++) { saltIndex = (fixByte(key[keyIndex]) + salt[i] + saltIndex) % 256; swap( salt, i, saltIndex ); keyIndex = (keyIndex + 1) % key.length; } }
/** * This will encrypt and write the data. * * @param data The data to encrypt. * @param output The stream to write to. * * @throws IOException If there is an error writing to the output stream. */ public void write( byte[] data, OutputStream output ) throws IOException { for (byte aData : data) { write(aData, output); } }
/** * Encrypt or decrypt data with RC4. * * @param finalKey The final key obtained with via {@link #calcFinalKey(long, long)}. * @param input The data to encrypt. * @param output The output to write the encrypted data to. * * @throws IOException If there is an error reading the data. */ protected void encryptDataRC4(byte[] finalKey, byte[] input, OutputStream output) throws IOException { rc4.setKey(finalKey); rc4.write(input, output); }
/** * This will encrypt and write the data. * * @param data The data to encrypt. * @param output The stream to write to. * * @throws IOException If there is an error writing to the output stream. */ public void write( byte[] data, OutputStream output ) throws IOException { for (byte aData : data) { write(aData, output); } }
/** * Encrypt or decrypt data with RC4. * * @param finalKey The final key obtained with via {@link #calcFinalKey(long, long)}. * @param input The data to encrypt. * @param output The output to write the encrypted data to. * * @throws IOException If there is an error reading the data. */ protected void encryptDataRC4(byte[] finalKey, InputStream input, OutputStream output) throws IOException { rc4.setKey(finalKey); rc4.write(input, output); }
/** * This will encrypt and write the data. * * @param data The data to encrypt. * @param offset The offset into the array to start reading data from. * @param len The number of bytes to attempt to read. * @param output The stream to write to. * * @throws IOException If there is an error writing to the output stream. */ public void write( byte[] data, int offset, int len, OutputStream output) throws IOException { for( int i = offset; i < offset + len; i++ ) { write( data[i], output ); } } }
/** * Encrypt or decrypt data with RC4. * * @param finalKey The final key obtained with via {@link #calcFinalKey(long, long)}. * @param input The data to encrypt. * @param output The output to write the encrypted data to. * * @throws IOException If there is an error reading the data. */ protected void encryptDataRC4(byte[] finalKey, InputStream input, OutputStream output) throws IOException { rc4.setKey(finalKey); rc4.write(input, output); }
/** * This will encrypt and write the data. * * @param data The data to encrypt. * @param offset The offset into the array to start reading data from. * @param len The number of bytes to attempt to read. * @param output The stream to write to. * * @throws IOException If there is an error writing to the output stream. */ public void write( byte[] data, int offset, int len, OutputStream output) throws IOException { for( int i = offset; i < offset + len; i++ ) { write( data[i], output ); } } }
/** * This will encrypt and write the data. * * @param data The data to encrypt. * @param output The stream to write to. * * @throws IOException If there is an error writing to the output stream. */ public void write( InputStream data, OutputStream output ) throws IOException { byte[] buffer = new byte[1024]; int amountRead; while( (amountRead = data.read( buffer )) != -1 ) { write( buffer, 0, amountRead, output ); } }