コード例 #1
0
            public void Dispose()
            {
                _decryptor?.Dispose();
                _encryptor?.Dispose();

                _symmetricAlgorithm.Dispose();
            }
コード例 #2
0
 public override void Close()
 {
     cryptoStream.Dispose();
     stream.Dispose();
     symmetricAlgorithm.Dispose();
     cryptoTransform.Dispose();
 }
コード例 #3
0
ファイル: Symmetric.cs プロジェクト: yousky/BWYouCore
 public void Dispose()
 {
     if (symmetric != null)
     {
         symmetric.Dispose();
     }
 }
コード例 #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;
            }
        }
コード例 #5
0
 public void Dispose()
 {
     if (algorithm != null)
     {
         algorithm.Dispose();
     }
 }
コード例 #6
0
ファイル: RecordLayer.cs プロジェクト: xuzhe35/netmq
        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;
            }
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: stevoat8/ItaProgExtension
        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);
        }
コード例 #8
0
ファイル: CryptoSymm.cs プロジェクト: rgl/TSS.MSR
        public void Dispose()
        {
#if TSS_USE_BCRYPT
            Key.Dispose();
#else
            Alg.Dispose();
#endif
        }
コード例 #9
0
 private void Dispose(bool Disposing)
 {
     if (!_disposed)
     {
         _symAlgo.Dispose();
         _disposed = true;
     }
 }
コード例 #10
0

        
コード例 #11
0
ファイル: SaltedHash.cs プロジェクト: NagababuCGvak/B4YMLive
 public void Release()
 {
     IsReleased = true;
     //_hashAlgorithm.Clear();
     //_symmetricAlgorithm.Clear();
     _hashAlgorithm.Clear();
     _symmetricAlgorithm.Dispose();
 }
コード例 #12
0
        public static void ReleaseSymmetricAlgorithm(this CryptoProviderFactory _, SymmetricAlgorithm symmetricAlgorithm)
        {
            if (symmetricAlgorithm == null)
            {
                throw LogHelper.LogArgumentNullException(nameof(symmetricAlgorithm));
            }

            symmetricAlgorithm.Dispose();
        }
コード例 #13
0
ファイル: FipsEncryptor.cs プロジェクト: ravendb/silverlight
            public void Dispose()
            {
#if !SILVERLIGHT
                if (algorithm != null)
                {
                    algorithm.Dispose();
                }
#endif
            }
コード例 #14
0
        public void Dispose()
        {
            if (mCryptoService != null)
            {
                mCryptoService.Dispose();
                mCryptoService = null;
            }

            GC.SuppressFinalize(this);
        }
コード例 #15
0
        public void Teardown()
        {
            if (algorithm != null)
            {
                algorithm.Dispose();
            }

            mKey = null;
            mIv  = null;
        }
コード例 #16
0
        public void Dispose()
        {
            _encryptor?.Dispose();
            _decryptor?.Dispose();

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

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    _symmetricAlgorithm.Dispose();
                }
                disposedValue = true;
            }
        }
コード例 #19
0
ファイル: Cipher.cs プロジェクト: nasraldin/CodeZero
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (encrypto != null)
         {
             encrypto.Dispose();
             encrypto = null;
         }
     }
 }
コード例 #20
0
 protected virtual void Dispose(bool disposing)
 {
     if (!disposed)
     {
         if (disposing)
         {
             blow.Dispose();
         }
         DisposeHelper.OnDispose <BlowfishCryptoProvider>(disposing);
         disposed = true;
     }
 }
コード例 #21
0
ファイル: Program25.cs プロジェクト: LLLXXXCCC/ConsoleApp27
    public void TestMethod(byte[] key, byte[] someOtherBytesForIV)
    {
        string someHardCodedBase64String = "sssdsdsdsdsdsds" +
                                           "sdasdsadasddsda" +
                                           "sdasdsadasddsda";

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

        rijn.CreateEncryptor(key, someOtherBytesForIV);
        rijn.Dispose();
    }
コード例 #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();
         }
     }
 }
コード例 #23
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         // free managed resources
         if (saltGenerator != null)
         {
             saltGenerator.Dispose();
         }
         if (algorithm != null)
         {
             algorithm.Dispose();
         }
     }
 }
コード例 #24
0
 void IDisposable.Dispose()
 {
     if (mRawDataStream != null)
     {
         mRawDataStream.Dispose();
     }
     if (mAlgorithm != null)
     {
         mAlgorithm.Dispose();
     }
     if (mTransform != null)
     {
         mTransform.Dispose();
     }
 }
コード例 #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;
            }
        }
コード例 #26
0
        /// <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;
                }
            }
        }
コード例 #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;
            }
        }
コード例 #28
0
        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;
            }
        }
コード例 #29
0
        public override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_cryptoAlgorithm != null)
                {
                    _cryptoAlgorithm.Dispose();
                    _cryptoAlgorithm = null;
                }

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

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

            _disposed = true;
        }