protected virtual void Dispose(bool disposing)
        {
            lock (this)
            {
                if (_disposed)
                {
                    return;
                }
                _disposed = true;
            }

            if (disposing)
            {
                if (_encryptCtx != IntPtr.Zero)
                {
                    Libcrypto.clean(_encryptCtx);
                }
                if (_decryptCtx != IntPtr.Zero)
                {
                    Libcrypto.clean(_decryptCtx);
                }
                _encryptCtx = IntPtr.Zero;
                _decryptCtx = IntPtr.Zero;
            }
        }
 protected override void cipherUpdate(bool isCipher, int length, byte[] buf, byte[] outbuf)
 {
     if (_disposed)
     {
         throw new ObjectDisposedException(this.ToString());
     }
     int len = Libcrypto.update(isCipher ? _encryptCtx : _decryptCtx, buf, length, outbuf);
 }
        public static void InitAviable()
        {
            List <string> remove_ciphers = new List <string>();

            foreach (string cipher in _ciphers.Keys)
            {
                if (!Libcrypto.is_cipher(cipher))
                {
                    remove_ciphers.Add(cipher);
                }
            }
            foreach (string cipher in remove_ciphers)
            {
                _ciphers.Remove(cipher);
            }
        }
        protected override void initCipher(byte[] iv, bool isCipher)
        {
            base.initCipher(iv, isCipher);

            IntPtr ctx;

            byte[] realkey;
            if (_method.StartsWith("rc4-md5"))
            {
                byte[] temp = new byte[keyLen + ivLen];
                realkey = new byte[keyLen];
                Array.Copy(_key, 0, temp, 0, keyLen);
                Array.Copy(iv, 0, temp, keyLen, ivLen);
                realkey = MbedTLS.MD5(temp);
            }
            else
            {
                realkey = _key;
            }
            if (isCipher)
            {
                if (_encryptCtx == IntPtr.Zero)
                {
                    ctx         = Libcrypto.init(Method, realkey, iv, 1);
                    _encryptCtx = ctx;
                }
                else
                {
                    ctx = _encryptCtx;
                }
            }
            else
            {
                if (_decryptCtx == IntPtr.Zero)
                {
                    ctx         = Libcrypto.init(Method, realkey, iv, 0);
                    _decryptCtx = ctx;
                }
                else
                {
                    ctx = _decryptCtx;
                }
            }
        }
 public static bool isSupport()
 {
     return(Libcrypto.isSupport());
 }