RC4 ExampleRC4 is a stream cipher used in WEP (in wireless encryption). [Theory] Encrypted (Base-64) Encrypted (Hex) Decrypted |
Code Used
public string rc4encrypt(string msg, string key) { RC4Engine inCipher = new RC4Engine(); inCipher.Init(false, new KeyParameter(StringToByte(key))); byte[] outcipher = new byte[msg.Length]; inCipher.ProcessBytes(StringToByte(msg), 0, msg.Length, outcipher, 0); return(Convert.ToBase64String(outcipher)); } public string rc4decrypt(string msg, string key) { RC4Engine inCipher = new RC4Engine(); inCipher.Init(false, new KeyParameter(StringToByte(key))); byte [] instr=Convert.FromBase64String(msg); byte[] outcipher = new byte[instr.Length]; inCipher.ProcessBytes(instr,0,instr.Length, outcipher, 0); return (ByteToAscii(outcipher)); } public static string ByteToAscii(byte[] buff) { string sbinary = ""; for (int i = 0; i < buff.Length; i++) { sbinary += (char)buff[i]; // hex format } return (sbinary); }