RC4 library functions
This library includes functions for encoding data using te RC4 encryption standard.
Adopted from RC4 encoding function found here:
http://forums.alliedmods.net/showthread.php?t=69349
RC4 is an older encryption method that is no longer considered "secure" due to known vunerabilities and biases in the encryption process. However, it is simple and efficient to perform and it is plenty secure for scenarios where you're not storing or transmitting really important or private data, such as credit card numbers.
These functions are ideally suited for including sensitive or secure data in a data stream or URL to a web server.
Note that raw RC4 output is binary data and is not URL safe. I recommend converting to Base64 using
this Base64 library file.
EncodeRC4
EncodeRC4(const String:input[], const String:pwd[], String:output[], maxlen)
Encrypts a text string using RC4.
- input: The source data to be encrypted.
- pwd: The password/key used to encode and decode the data.
- output: The encoded result.
- maxlen: The maximum length of the output buffer.
Return: None.
Note: This function is NOT binary safe. Use EncodeRC4Binary to encode binary data.
EncodeRC4Binary
EncodeRC4Binary(const String:input[], str_len, const String:pwd[], String:output[], maxlen)
Encrypts binary data using RC4.
- input: The source data to be encrypted.
- str_len: The length of the source data.
- pwd: The password/key used to encode and decode the data.
- output: The encoded result.
- maxlen: The maximum length of the output buffer.
Return: None.
For an example application, check out the Jukebox for Source plugin, written by myself:
http://forums.alliedmods.net/showthread.php?t=100537
Here, I use RC4 to encrypt a timestamp into the URLs. This is used to impose an expiry on issued URLs, to stop other game servers from leeching on the music service.