public byte[] DecryptMessage(byte[] cipherText, int length) { if (cipherText == null) throw new ArgumentNullException("cipherText"); if (length > cipherText.Length) throw new ArgumentOutOfRangeException("length", "Bad length during Decryption: the length parameter must be smaller than or equal to the size of the destination array."); byte[] plainText = new byte[length]; for (int i = 0; i < length; i++) { byte C = (byte)(cipherText[i] ^ MagicByte); UpdateKeys(C); plainText[i] = C; } return plainText; }
public override int Read(byte[] buffer, int offset, int count) { if (_mode == CryptoMode.Encrypt) { throw new NotSupportedException("This stream does not encrypt via Read()"); } if (buffer == null) { throw new ArgumentNullException("buffer"); } byte[] db = new byte[count]; int n = _s.Read(db, 0, count); byte[] decrypted = _cipher.DecryptMessage(db, n); for (int i = 0; i < n; i++) { buffer[offset + i] = decrypted[i]; } return(n); }