EncryptMessage() public method

This is the converse of DecryptMessage. It encrypts the plaintext and produces a ciphertext.
public EncryptMessage ( byte plainText, int length ) : byte[]
plainText byte The plain text buffer.
length int /// The number of bytes to encrypt. /// Should be less than or equal to plainText.Length. ///
return byte[]
Ejemplo n.º 1
0
        public override void Write(byte[] buffer, int offset, int count)
        {
            if (_mode == CryptoMode.Decrypt)
            {
                throw new NotSupportedException("This stream does not Decrypt via Write()");
            }

            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            // workitem 7696
            if (count == 0)
            {
                return;
            }

            byte[] plaintext = null;
            if (offset != 0)
            {
                plaintext = new byte[count];
                for (int i = 0; i < count; i++)
                {
                    plaintext[i] = buffer[offset + i];
                }
            }
            else
            {
                plaintext = buffer;
            }

            byte[] encrypted = _cipher.EncryptMessage(plaintext, count);
            _s.Write(encrypted, 0, encrypted.Length);
        }