public void Dispose()
            {
                _decryptor?.Dispose();
                _encryptor?.Dispose();

                _symmetricAlgorithm.Dispose();
            }
Beispiel #2
0
 public override void Close()
 {
     cryptoStream.Dispose();
     stream.Dispose();
     symmetricAlgorithm.Dispose();
     cryptoTransform.Dispose();
 }
Beispiel #3
0
 public void Dispose()
 {
     if (symmetric != null)
     {
         symmetric.Dispose();
     }
 }
Beispiel #4
0
        protected virtual SymmetricAlgorithm CreateAlgorithm(ApplicationContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            SymmetricAlgorithm alg = null;

            try
            {
                alg = CreateAlgorithmImpl(context);
                var salt = GetSaltBytes(context);

                using (var pbkdf2 = new Rfc2898DeriveBytes(context.Secret, salt, DefaultIterationsCount))
                {
                    alg.Key = pbkdf2.GetBytes(32);
                    alg.IV  = pbkdf2.GetBytes(16);
                }

                return(alg);
            }
            catch (Exception)
            {
                alg?.Dispose();
                throw;
            }
        }
Beispiel #5
0
 public void Dispose()
 {
     if (algorithm != null)
     {
         algorithm.Dispose();
     }
 }
Beispiel #6
0
        public void Dispose()
        {
            if (m_decryptionBulkAlgorithm != null)
            {
                m_decryptionBulkAlgorithm.Dispose();
                m_decryptionBulkAlgorithm = null;
            }

            if (m_encryptionBulkAlgorithm != null)
            {
                m_encryptionBulkAlgorithm.Dispose();
                m_encryptionBulkAlgorithm = null;
            }

            if (m_decryptionHMAC != null)
            {
                m_decryptionHMAC.Dispose();
                m_decryptionHMAC = null;
            }

            if (m_encryptionHMAC != null)
            {
                m_encryptionHMAC.Dispose();
                m_encryptionHMAC = null;
            }

            if (PRF != null)
            {
                PRF.Dispose();
                PRF = null;
            }
        }
Beispiel #7
0
        private static byte[] CryptoTransform(
            string fileName, CryptoTransformOperationsEnum operation, SymmetricAlgorithm algo)
        {
            byte[] orignalFile = File.ReadAllBytes(fileName);
            byte[] processedFile;

            ICryptoTransform cryptoTransform;

            switch (operation)
            {
            case CryptoTransformOperationsEnum.Encrypt:
                cryptoTransform = algo.CreateEncryptor();
                break;

            case CryptoTransformOperationsEnum.Decrypt:
                cryptoTransform = algo.CreateDecryptor();
                break;

            default:
                throw new Exception();
            }

            using (MemoryStream memoryStream = new MemoryStream())
            {
                using (CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform, CryptoStreamMode.Write))
                {
                    cryptoStream.Write(orignalFile, 0, orignalFile.Length);
                }
                algo.Dispose();
                processedFile = memoryStream.ToArray();
            }
            return(processedFile);
        }
Beispiel #8
0
        public void Dispose()
        {
#if TSS_USE_BCRYPT
            Key.Dispose();
#else
            Alg.Dispose();
#endif
        }
 private void Dispose(bool Disposing)
 {
     if (!_disposed)
     {
         _symAlgo.Dispose();
         _disposed = true;
     }
 }
Beispiel #10
0

        
Beispiel #11
0
 public void Release()
 {
     IsReleased = true;
     //_hashAlgorithm.Clear();
     //_symmetricAlgorithm.Clear();
     _hashAlgorithm.Clear();
     _symmetricAlgorithm.Dispose();
 }
Beispiel #12
0
        public static void ReleaseSymmetricAlgorithm(this CryptoProviderFactory _, SymmetricAlgorithm symmetricAlgorithm)
        {
            if (symmetricAlgorithm == null)
            {
                throw LogHelper.LogArgumentNullException(nameof(symmetricAlgorithm));
            }

            symmetricAlgorithm.Dispose();
        }
Beispiel #13
0
            public void Dispose()
            {
#if !SILVERLIGHT
                if (algorithm != null)
                {
                    algorithm.Dispose();
                }
#endif
            }
Beispiel #14
0
        public void Dispose()
        {
            if (mCryptoService != null)
            {
                mCryptoService.Dispose();
                mCryptoService = null;
            }

            GC.SuppressFinalize(this);
        }
        public void Teardown()
        {
            if (algorithm != null)
            {
                algorithm.Dispose();
            }

            mKey = null;
            mIv  = null;
        }
        public void Dispose()
        {
            _encryptor?.Dispose();
            _decryptor?.Dispose();

            if (_disposeAlgorithm)
            {
                _algorithm.Dispose();
            }
        }
Beispiel #17
0
 protected virtual void Dispose(bool disposing)
 {
     if (_disposed == false)
     {
         _disposed = true;
         if (disposing == true)
         {
             control.Dispose();
         }
     }
 }
Beispiel #18
0
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    _symmetricAlgorithm.Dispose();
                }
                disposedValue = true;
            }
        }
Beispiel #19
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (encrypto != null)
         {
             encrypto.Dispose();
             encrypto = null;
         }
     }
 }
Beispiel #20
0
 protected virtual void Dispose(bool disposing)
 {
     if (!disposed)
     {
         if (disposing)
         {
             blow.Dispose();
         }
         DisposeHelper.OnDispose <BlowfishCryptoProvider>(disposing);
         disposed = true;
     }
 }
Beispiel #21
0
    public void TestMethod(byte[] key, byte[] someOtherBytesForIV)
    {
        string someHardCodedBase64String = "sssdsdsdsdsdsds" +
                                           "sdasdsadasddsda" +
                                           "sdasdsadasddsda";

        A();
        B();
        SymmetricAlgorithm rijn = SymmetricAlgorithm.Create();

        rijn.CreateEncryptor(key, someOtherBytesForIV);
        rijn.Dispose();
    }
Beispiel #22
0
 /// <summary>
 /// Releases the unmanaged resources used by the <c>EncryptionReader</c> class and optionally
 /// releases the managed resources.
 /// </summary>
 /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources;
 /// <c>false</c> to release only unmanaged resources.</param>
 protected override void Dispose(bool disposing)
 {
     if (!disposed)
     {
         disposed = true;
         if (disposing)
         {
             // Dispose managed objects
             base.Dispose(true);
             Decryptor.Dispose();
             Algorithm.Dispose();
         }
     }
 }
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         // free managed resources
         if (saltGenerator != null)
         {
             saltGenerator.Dispose();
         }
         if (algorithm != null)
         {
             algorithm.Dispose();
         }
     }
 }
Beispiel #24
0
 void IDisposable.Dispose()
 {
     if (mRawDataStream != null)
     {
         mRawDataStream.Dispose();
     }
     if (mAlgorithm != null)
     {
         mAlgorithm.Dispose();
     }
     if (mTransform != null)
     {
         mTransform.Dispose();
     }
 }
Beispiel #25
0
        /// <summary>
        /// Dispose of all contained resources.
        /// </summary>
        public void Dispose()
        {
            if (m_decryptionBulkAlgorithm != null)
            {
#if NET40
                m_decryptionBulkAlgorithm.Dispose();
#else
                m_decryptionBulkAlgorithm.Clear();
#endif
                m_decryptionBulkAlgorithm = null;
            }

            if (m_encryptionBulkAlgorithm != null)
            {
#if NET40
                m_encryptionBulkAlgorithm.Dispose();
#else
                m_encryptionBulkAlgorithm.Clear();
#endif
                m_encryptionBulkAlgorithm = null;
            }

            if (m_decryptionHMAC != null)
            {
#if NET40
                m_decryptionHMAC.Dispose();
#else
                m_decryptionHMAC.Clear();
#endif
                m_decryptionHMAC = null;
            }

            if (m_encryptionHMAC != null)
            {
#if NET40
                m_encryptionHMAC.Dispose();
#else
                m_encryptionHMAC.Clear();
#endif
                m_encryptionHMAC = null;
            }

            if (PRF != null)
            {
                PRF.Dispose();
                PRF = null;
            }
        }
        /// <summary>
        /// Disposes of internal components.
        /// </summary>
        /// <param name="disposing">true, if called from Dispose(), false, if invoked inside a finalizer.</param>
        protected override void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    if (_symmetricAlgorithm != null)
                    {
                        _symmetricAlgorithm.Dispose();
                        _symmetricAlgorithm = null;
                    }

                    _disposed = true;
                }
            }
        }
Beispiel #27
0
        // Dispose(bool disposing) executes in two distinct scenarios.
        // If disposing equals true, the method has been called directly
        // or indirectly by a user's code. Managed and unmanaged resources
        // can be disposed.
        // If disposing equals false, the method has been called by the
        // runtime from inside the finalizer and you should not reference
        // other objects. Only unmanaged resources can be disposed.
        protected virtual void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!this.disposed)
            {
                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if (disposing)
                {
                    // Dispose managed resources.
                    _algorithm.Dispose();
                }

                // Note disposing has been done.
                disposed = true;
            }
        }
        private void btnEncodeText_Click(object sender, EventArgs e)
        {
            // legal sizes for AES Key = (128 to 256)/block size(currently 8), so 24*8=192
            // legal sizes for AES IV = 128/block size(currently 8), so 16*8=128
            // legal sizes for key in TripleDES is 128-192, IV seems to be mulitples of 8
            baKeyString = Encoding.UTF8.GetBytes(txtKeyString.Text);
            if (rbAES.Checked)
            {
                baIVstring = Encoding.UTF8.GetBytes(txtIVstring.Text.Substring(0, 16));
            }
            else if (rbTripleDES.Checked)
            {
                // seems to have the native ability to trim the string to what it wants
                baIVstring = Encoding.UTF8.GetBytes(txtIVstring.Text);
            }
            SymmetricAlgorithm oAlgorithm = null;

            if (rbTripleDES.Checked)
            {
                oAlgorithm = TripleDES.Create();
            }
            else if (rbAES.Checked)
            {
                oAlgorithm = Aes.Create();
            }
            ICryptoTransform oTransform = oAlgorithm.CreateEncryptor(baKeyString, baIVstring);

            try
            {
                byte[] inputbuffer = Encoding.Unicode.GetBytes(txtInputString.Text);
                outputbuffer         = oTransform.TransformFinalBlock(inputbuffer, 0, inputbuffer.Length);
                txtOutputString.Text = Convert.ToBase64String(outputbuffer);
            }
            catch (Exception e9)
            {
                MessageBox.Show(this, "Error encoding!\n" + e9.Message);
            }
            finally
            {
                oTransform.Dispose();
                oTransform = null;
                oAlgorithm.Clear();
                oAlgorithm.Dispose();
                oAlgorithm = null;
            }
        }
Beispiel #29
0
        public override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_cryptoAlgorithm != null)
                {
                    _cryptoAlgorithm.Dispose();
                    _cryptoAlgorithm = null;
                }

                if (_encryptor != null)
                {
                    _encryptor.Dispose();
                    _encryptor = null;
                }
            }
        }
Beispiel #30
0
        private void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                if (_symAlgo != null)
                {
                    _symAlgo.Dispose();
                }
            }

            _disposed = true;
        }