You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

EncryptorFactory.cs 1.4 kB

10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
10 years ago
9 years ago
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839
  1. 
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Reflection;
  5. namespace Shadowsocks.Encryption
  6. {
  7. public static class EncryptorFactory
  8. {
  9. private static Dictionary<string, Type> _registeredEncryptors;
  10. private static Type[] _constructorTypes = new Type[] { typeof(string), typeof(string), typeof(bool), typeof(bool) };
  11. static EncryptorFactory()
  12. {
  13. _registeredEncryptors = new Dictionary<string, Type>();
  14. foreach (string method in PolarSSLEncryptor.SupportedCiphers())
  15. {
  16. _registeredEncryptors.Add(method, typeof(PolarSSLEncryptor));
  17. }
  18. foreach (string method in SodiumEncryptor.SupportedCiphers())
  19. {
  20. _registeredEncryptors.Add(method, typeof(SodiumEncryptor));
  21. }
  22. }
  23. public static IEncryptor GetEncryptor(string method, string password, bool onetimeauth, bool isudp)
  24. {
  25. if (method.IsNullOrEmpty())
  26. {
  27. method = "aes-256-cfb";
  28. }
  29. method = method.ToLowerInvariant();
  30. Type t = _registeredEncryptors[method];
  31. ConstructorInfo c = t.GetConstructor(_constructorTypes);
  32. IEncryptor result = (IEncryptor)c.Invoke(new object[] { method, password, onetimeauth, isudp });
  33. return result;
  34. }
  35. }
  36. }