Exemplo n.º 1
0
 private void Dispose(bool Disposing)
 {
     if (!m_isDisposed && Disposing)
     {
         try
         {
             if (m_disposeEngine)
             {
                 if (m_cipherEngine != null)
                 {
                     m_cipherEngine.Dispose();
                     m_cipherEngine = null;
                 }
                 if (m_streamCipher != null)
                 {
                     m_streamCipher.Dispose();
                     m_streamCipher = null;
                 }
             }
         }
         finally
         {
             m_isDisposed = true;
         }
     }
 }
Exemplo n.º 2
0
        private void Dispose(bool Disposing)
        {
            if (!_isDisposed && Disposing)
            {
                // destroys cipher and engine
                if (this.Mode != null)
                {
                    this.Mode.Dispose();
                }

                if (this.StreamCipher != null)
                {
                    StreamCipher.Dispose();
                }

                if (this.Key != null)
                {
                    Array.Clear(this.Key, 0, this.Key.Length);
                    this.Key = null;
                }
                if (this.IV != null)
                {
                    Array.Clear(this.IV, 0, this.IV.Length);
                    this.IV = null;
                }
                _isDisposed = true;
            }
        }
Exemplo n.º 3
0
        void StreamingTest(IStreamCipher Cipher)
        {
            AllocateRandom(ref _plnText);
            AllocateRandom(ref _iv, 8);
            AllocateRandom(ref _key, 32);

            KeyParams    kp   = new KeyParams(_key, _iv);
            MemoryStream mIn  = new MemoryStream(_plnText);
            MemoryStream mOut = new MemoryStream();
            MemoryStream mRes = new MemoryStream();

            CipherStream cs = new CipherStream(Cipher);

            cs.Initialize(true, kp);
            cs.Write(mIn, mOut);

            mOut.Seek(0, SeekOrigin.Begin);

            cs.Initialize(false, kp);
            cs.Write(mOut, mRes);
            Cipher.Dispose();

            if (!Evaluate.AreEqual(mRes.ToArray(), _plnText))
            {
                throw new Exception("CipherStreamTest: Encrypted arrays are not equal!");
            }
        }