Exemple #1
0
        static EncryptorFactory()
        {
            foreach (var method in NoneEncryptor.SupportedCiphers())
            {
                if (!_registeredEncryptors.ContainsKey(method))
                {
                    _registeredEncryptors.Add(method, typeof(NoneEncryptor));
                }
            }

            foreach (var method in StreamOpenSSLEncryptor.SupportedCiphers())
            {
                if (!_registeredEncryptors.ContainsKey(method))
                {
                    _registeredEncryptors.Add(method, typeof(StreamOpenSSLEncryptor));
                }
            }


            foreach (var method in StreamSodiumEncryptor.SupportedCiphers())
            {
                if (!_registeredEncryptors.ContainsKey(method))
                {
                    _registeredEncryptors.Add(method, typeof(StreamSodiumEncryptor));
                }
            }

            foreach (var method in StreamMbedTLSEncryptor.SupportedCiphers())
            {
                if (!_registeredEncryptors.ContainsKey(method))
                {
                    _registeredEncryptors.Add(method, typeof(StreamMbedTLSEncryptor));
                }
            }
        }
        static EncryptorFactory()
        {
            foreach (var method in NoneEncryptor.SupportedCiphers().Where(method => !RegisteredEncryptors.ContainsKey(method)))
            {
                RegisteredEncryptors.Add(method, typeof(NoneEncryptor));
            }

            foreach (var method in StreamOpenSSLEncryptor.SupportedCiphers().Where(method => !RegisteredEncryptors.ContainsKey(method)))
            {
                RegisteredEncryptors.Add(method, typeof(StreamOpenSSLEncryptor));
            }

            foreach (var method in StreamSodiumEncryptor.SupportedCiphers().Where(method => !RegisteredEncryptors.ContainsKey(method)))
            {
                RegisteredEncryptors.Add(method, typeof(StreamSodiumEncryptor));
            }

            foreach (var method in StreamMbedTLSEncryptor.SupportedCiphers().Where(method => !RegisteredEncryptors.ContainsKey(method)))
            {
                RegisteredEncryptors.Add(method, typeof(StreamMbedTLSEncryptor));
            }

            var allEncryptor = new StringBuilder(Environment.NewLine);

            allEncryptor.AppendLine(@"============================");
            allEncryptor.AppendLine(@"Registered Encryptor Info");
            foreach (var encryptor in RegisteredEncryptors)
            {
                allEncryptor.AppendLine($@"{encryptor.Key}=>{encryptor.Value.Name}");
            }
            allEncryptor.AppendLine(@"============================");
            Console.WriteLine(allEncryptor);
        }
        static EncryptorFactory()
        {
            _registeredEncryptors     = new Dictionary <string, Type>();
            _registeredEncryptorNames = new List <string>();
            foreach (string method in NoneEncryptor.SupportedCiphers())
            {
                if (!_registeredEncryptorNames.Contains(method))
                {
                    _registeredEncryptorNames.Add(method);
                    _registeredEncryptors.Add(method, typeof(NoneEncryptor));
                }
            }

            {
                foreach (string method in MbedTLSEncryptor.SupportedCiphers())
                {
                    if (!_registeredEncryptorNames.Contains(method))
                    {
                        _registeredEncryptorNames.Add(method);
                        _registeredEncryptors.Add(method, typeof(MbedTLSEncryptor));
                    }
                }
            }
            if (LibcryptoEncryptor.isSupport())
            {
                LibcryptoEncryptor.InitAviable();
                foreach (string method in LibcryptoEncryptor.SupportedCiphers())
                {
                    if (!_registeredEncryptorNames.Contains(method))
                    {
                        _registeredEncryptorNames.Add(method);
                        _registeredEncryptors.Add(method, typeof(LibcryptoEncryptor));
                    }
                }
            }
            foreach (string method in SodiumEncryptor.SupportedCiphers())
            {
                if (!_registeredEncryptorNames.Contains(method))
                {
                    _registeredEncryptorNames.Add(method);
                    _registeredEncryptors.Add(method, typeof(SodiumEncryptor));
                }
            }
        }