Exemplo n.º 1
0
        public static EncryptorInfo GetEncryptorInfo(string method)
        {
            if (string.IsNullOrEmpty(method))
            {
                method = "none";
            }
            method = method.ToLowerInvariant();
            Type            t      = _registeredEncryptors[method];
            ConstructorInfo c      = t.GetConstructor(_constructorTypes);
            IEncryptor      result = (IEncryptor)c.Invoke(new object[] { method, "0" });
            EncryptorInfo   info   = result.getInfo();

            result.Dispose();
            return(info);
        }
Exemplo n.º 2
0
        protected void InitKey(string method, string password)
        {
            method  = method.ToLower();
            _method = method;
            string k = method + ":" + password;

            ciphers     = getCiphers();
            _cipherInfo = ciphers[_method];
            _cipher     = _cipherInfo.type;
            if (_cipher == 0)
            {
                throw new Exception("method not found");
            }
            keyLen = ciphers[_method].key_size;
            ivLen  = ciphers[_method].iv_size;
            if (!CachedKeys.ContainsKey(k))
            {
                lock (CachedKeys)
                {
                    if (!CachedKeys.ContainsKey(k))
                    {
                        byte[] passbuf = Encoding.UTF8.GetBytes(password);
                        _key = new byte[32];
                        byte[] iv = new byte[16];
                        bytesToKey(passbuf, _key);
                        CachedKeys[k] = _key;
                    }
                }
            }
            if (_key == null)
            {
                _key = CachedKeys[k];
            }
            Array.Resize(ref _iv, ivLen);
            randBytes(_iv, ivLen);
        }