Class ARC4
- All Implemented Interfaces:
AutoCloseable
- init(seed, len): sets the key (seed) and initializes the RC4 cipher. - updateData(data, len): applies RC4 "in-place" on the buffer.
Note: RC4 is considered a weak cipher by modern standards and should not be used for secure applications. This implementation is provided for compatibility with existing code that uses RC4, but it is recommended to use stronger algorithms (like AES) for new development.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()"Replaces" the C++ destructor to release references/state.voidinit(byte[] seed, int len) Equivalent to Init(uint8* seed, size_t len) where 'seed' is the key and 'len' is the key length.voidupdateData(byte[] data, int len) Equivalent to UpdateData(uint8* data, size_t len) performing "in-place" processing.
-
Constructor Details
-
ARC4
public ARC4()Constructor initializes the Cipher instance for ARC4. The actual key is set in the init() method, allowing for dynamic key lengths.
-
-
Method Details
-
init
public void init(byte[] seed, int len) Equivalent to Init(uint8* seed, size_t len) where 'seed' is the key and 'len' is the key length. For RC4, the key can be of variable length (commonly between 1 and 256 bytes). -
updateData
public void updateData(byte[] data, int len) Equivalent to UpdateData(uint8* data, size_t len) performing "in-place" processing. For RC4, encryption/decryption is the same operation (stream cipher).Note: The method modifies the input 'data' array directly, similar to how the C++ code operates on the same buffer for input and output. The OpenSSL code calls EVP_EncryptUpdate with the same buffer for input and output, and then calls EVP_EncryptFinal_ex (which does not add any bytes for RC4). In Java, we use cipher.update() for the main processing and then call doFinal() to finalize the cipher state. For RC4, doFinal() should not produce additional output, but it is called to maintain consistency with the OpenSSL flow.
- Parameters:
data- The input data to be encrypted/decrypted in-place.len- The number of bytes from 'data' to process. Must be non-negative and not exceed data.length.
-
close
public void close()"Replaces" the C++ destructor to release references/state. (There is no explicit free like EVP_CIPHER_CTX_free, but this helps prevent reuse.)- Specified by:
closein interfaceAutoCloseable
-