Exemplo n.º 1
0
        public static EncryptorInfo GetEncryptorInfo(string method)
        {
            if (string.IsNullOrEmpty(method))
            {
                method = "aes-256-cfb";
            }
            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.Set(k, _key);
                        CachedKeys.Sweep();
                    }
                }
            }
            if (_key == null)
            {
                _key = CachedKeys.Get(k);
            }
            Array.Resize(ref _iv, ivLen);
            randBytes(_iv, ivLen);
        }
Exemplo n.º 3
0
        private void InitKey(string method, string password)
        {
            method  = method.ToLower();
            _method = method;
            string k = method + ":" + password;

            ciphers       = getCiphers();
            CipherInfo    = ciphers[_method];
            _innerLibName = CipherInfo.InnerLibName;
            _cipher       = CipherInfo.Type;
            if (_cipher == 0)
            {
                throw new Exception("method not found");
            }
            keyLen = CipherInfo.KeySize;
            ivLen  = CipherInfo.IvSize;
            _key   = CachedKeys.GetOrAdd(k, (nk) =>
            {
                byte[] passbuf = Encoding.UTF8.GetBytes(password);
                byte[] key     = new byte[32];
                bytesToKey(passbuf, key);
                return(key);
            });
        }
Exemplo n.º 4
0
 private void InitKey(string method, string password)
 {
     method = method.ToLower();
     _method = method;
     string k = method + ":" + password;
     ciphers = getCiphers();
     _cipherInfo = ciphers[_method];
     _cipherMbedName = _cipherInfo.name;
     _cipher = _cipherInfo.type;
     if (_cipher == 0)
     {
         throw new Exception("method not found");
     }
     keyLen = _cipherInfo.key_size;
     ivLen = _cipherInfo.iv_size;
     _key = CachedKeys.GetOrAdd(k, (nk) =>
     {
         byte[] passbuf = Encoding.UTF8.GetBytes(password);
         byte[] key = new byte[32];
         bytesToKey(passbuf, key);
         return key;
     });
 }