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.

CryptoProvider.cs 1.7 kB

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using System.Collections.Generic;
  3. namespace Shadowsocks.Protocol.Shadowsocks.Crypto
  4. {
  5. static class CryptoProvider
  6. {
  7. static Dictionary<string, CryptoParameter> parameters = new Dictionary<string, CryptoParameter>
  8. {
  9. ["xchacha20-ietf-poly1305"] = new CryptoParameter { KeySize = 32, NonceSize = 24, TagSize = 16, Crypto = typeof(AeadXChaCha20Poly1305Crypto) },
  10. ["chacha20-ietf-poly1305"] = new CryptoParameter { KeySize = 32, NonceSize = 12, TagSize = 16, Crypto = typeof(AeadChaCha20Poly1305Crypto) },
  11. ["aes-256-gcm"] = new CryptoParameter { KeySize = 32, NonceSize = 12, TagSize = 16, Crypto = typeof(AeadAesGcmCrypto) },
  12. ["aes-192-gcm"] = new CryptoParameter { KeySize = 24, NonceSize = 12, TagSize = 16, Crypto = typeof(AeadAesGcmCrypto) },
  13. ["aes-128-gcm"] = new CryptoParameter { KeySize = 16, NonceSize = 12, TagSize = 16, Crypto = typeof(AeadAesGcmCrypto) },
  14. ["none"] = new CryptoParameter { KeySize = 0, NonceSize = 0, TagSize = 0, Crypto = typeof(UnsafeNoneCrypto) }
  15. };
  16. public static CryptoParameter GetCrypto(string method)
  17. {
  18. if (string.IsNullOrEmpty(method))
  19. {
  20. // todo
  21. //method = IoCManager.Container.Resolve<IDefaultCrypto>().GetDefaultMethod();
  22. }
  23. method = method.ToLowerInvariant();
  24. var ok = parameters.TryGetValue(method, out var t);
  25. if (!ok)
  26. {
  27. //t = parameters[DefaultCipher];
  28. throw new NotImplementedException();
  29. }
  30. return t;
  31. }
  32. }
  33. }