Exemple #1
0
        protected override void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                // note: we ALWAYS zeroize keys (disposing or not)

                // clear our copy of the secret key
                if (KeyValue != null)
                {
                    Array.Clear(KeyValue, 0, KeyValue.Length);
                }
                // clear the secret key (inside TripleDES)
                if (tdes != null)
                {
                    tdes.Clear();
                }

                if (disposing)
                {
                    // disposed managed stuff
                    KeyValue = null;
                    tdes     = null;
                }
                // ancestor
                base.Dispose(disposing);
                m_disposed = true;
            }
        }
Exemple #2
0
        public bool Decrypt(ref string value)
        {
            Byte[] tmp    = Convert.FromBase64String(value);
            string result = string.Empty;

            System.Security.Cryptography.TripleDES tripleDES = System.Security.Cryptography.TripleDES.Create();
            ICryptoTransform decryptor = tripleDES.CreateDecryptor(key, iv);

            using (MemoryStream ms = new MemoryStream(tmp)) {
                try {
                    using (CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read)) {
                        StreamReader reader = new StreamReader(cs);
                        result = reader.ReadLine();
                    }
                } catch (System.Security.Cryptography.CryptographicException ex) {
                    value = ex.Message;
                    return(false);
                }
            }
            tripleDES.Clear();
            value = result;
            return(true);
        }
Exemple #3
0
 // IDisposable methods
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         // dispose of our internal state
         if (des != null)
         {
             des.Clear();
         }
         if (m_encryptor != null)
         {
             m_encryptor.Dispose();
         }
         if (_cs != null)
         {
             _cs.Clear();
         }
         if (_ts != null)
         {
             _ts.Clear();
         }
     }
     base.Dispose(disposing);
 }