The author, at least to transfer the authentication data to the remote side - this is not good. If the knowledge of the login does not allow authentication, then why protect it? If it allows, then this is the same password. And in this case it is more correct to transfer the hash from this data (n. SHA256) + salt for introducing entropy.
Otherwise, you either use the hardware to speed up the work (eg, processor intrinsic), or the most
public void Xor(Byte[] data, Byte[] key) { for(int i = 0; i < data.Length; i++) data[i] ^= key[i % key.Length]; }
The only thing you can speed up here is to wrap in unsafe , take a pointer with fixed and work with bare memory, bypassing checks for going beyond the array, but in the case of the first cycle, the compiler will do it himself. Perhaps speed up access to the key.
And in .NET there really is a set of encryption algorithms, including symmetric ones. For example, the old man DES.
public static Byte[] DesEncrypt(UInt64 desKey, UInt64 desVector, Byte[] decryptedData) { Byte[] key = BitConverter.GetBytes(desKey); Byte[] vector = BitConverter.GetBytes(desVector); using (DESCryptoServiceProvider provider = new DESCryptoServiceProvider()) { provider.Padding = PaddingMode.Zeros; using (MemoryStream inputStream = new MemoryStream(decryptedData)) using (MemoryStream outputStream = new MemoryStream(decryptedData.Length)) using (ICryptoTransform transform = provider.CreateEncryptor(key, vector)) using (CryptoStream encStream = new CryptoStream(outputStream, transform, CryptoStreamMode.Write)) { inputStream.CopyTo(encStream); encStream.FlushFinalBlock(); return outputStream.ToArray(); } } } public static Byte[] DesDecrypt(UInt64 desKey, UInt64 desVector, Byte[] encryptedData) { Byte[] key = BitConverter.GetBytes(desKey); Byte[] vector = BitConverter.GetBytes(desVector); using (DESCryptoServiceProvider provider = new DESCryptoServiceProvider()) { provider.Padding = PaddingMode.Zeros; using (MemoryStream inputStream = new MemoryStream(encryptedData)) using (MemoryStream outputStream = new MemoryStream(encryptedData.Length)) using (ICryptoTransform transform = provider.CreateDecryptor(key, vector)) using (CryptoStream decStream = new CryptoStream(inputStream, transform, CryptoStreamMode.Read)) { decStream.CopyTo(outputStream); return outputStream.ToArray(); } } }