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.

EncryptorBase.cs 1.4 kB

10 years ago
10 years ago
10 years ago
10 years ago
9 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
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System.Text;
  2. namespace Shadowsocks.Encryption
  3. {
  4. public struct EncryptorInfo
  5. {
  6. public string name;
  7. public int key_size;
  8. public int iv_size;
  9. public int type;
  10. public EncryptorInfo(string name, int key_size, int iv_size, int type)
  11. {
  12. this.name = name;
  13. this.key_size = key_size;
  14. this.iv_size = iv_size;
  15. this.type = type;
  16. }
  17. }
  18. public abstract class EncryptorBase
  19. : IEncryptor
  20. {
  21. public const int MAX_INPUT_SIZE = 32768;
  22. protected EncryptorBase(string method, string password, bool onetimeauth, bool isudp)
  23. {
  24. Method = method;
  25. Password = password;
  26. OnetimeAuth = onetimeauth;
  27. IsUDP = isudp;
  28. }
  29. protected string Method;
  30. protected string Password;
  31. protected bool OnetimeAuth;
  32. protected bool IsUDP;
  33. protected byte[] GetPasswordHash()
  34. {
  35. byte[] inputBytes = Encoding.UTF8.GetBytes(Password);
  36. byte[] hash = MbedTLS.MD5(inputBytes);
  37. return hash;
  38. }
  39. public abstract void Encrypt(byte[] buf, int length, byte[] outbuf, out int outlength);
  40. public abstract void Decrypt(byte[] buf, int length, byte[] outbuf, out int outlength);
  41. public abstract void Dispose();
  42. }
  43. }