Crisis.Ionic.Zip.ZipCrypto.DecryptMessage C# (CSharp) Method

DecryptMessage() public method

Call this method on a cipher text to render the plaintext. You must first initialize the cipher with a call to InitCipher.
public DecryptMessage ( byte cipherText, int length ) : byte[]
cipherText byte The encrypted buffer.
length int /// The number of bytes to encrypt. /// Should be less than or equal to CipherText.Length. ///
return byte[]
        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;
        }

Usage Example

Example #1
0
        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);
        }
All Usage Examples Of Crisis.Ionic.Zip.ZipCrypto::DecryptMessage