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.8 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
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System.Text;
  2. namespace Shadowsocks.Encryption
  3. {
  4. public struct EncryptorInfo
  5. {
  6. public int KeySize;
  7. public int IvSize;
  8. public int Type;
  9. public string InnerLibName;
  10. // For those who make use of internal crypto method name
  11. // e.g. mbed TLS
  12. public EncryptorInfo(string innerLibName, int keySize, int ivSize, int type)
  13. {
  14. this.KeySize = keySize;
  15. this.IvSize = ivSize;
  16. this.Type = type;
  17. this.InnerLibName = innerLibName;
  18. }
  19. public EncryptorInfo(int keySize, int ivSize, int type)
  20. {
  21. this.KeySize = keySize;
  22. this.IvSize = ivSize;
  23. this.Type = type;
  24. this.InnerLibName = string.Empty;
  25. }
  26. }
  27. public abstract class EncryptorBase
  28. : IEncryptor
  29. {
  30. public const int MAX_INPUT_SIZE = 32768;
  31. protected EncryptorBase(string method, string password, bool onetimeauth, bool isudp)
  32. {
  33. Method = method;
  34. Password = password;
  35. OnetimeAuth = onetimeauth;
  36. IsUDP = isudp;
  37. }
  38. protected string Method;
  39. protected string Password;
  40. protected bool OnetimeAuth;
  41. protected bool IsUDP;
  42. protected byte[] GetPasswordHash()
  43. {
  44. byte[] inputBytes = Encoding.UTF8.GetBytes(Password);
  45. byte[] hash = MbedTLS.MD5(inputBytes);
  46. return hash;
  47. }
  48. public abstract void Encrypt(byte[] buf, int length, byte[] outbuf, out int outlength);
  49. public abstract void Decrypt(byte[] buf, int length, byte[] outbuf, out int outlength);
  50. public abstract void Dispose();
  51. }
  52. }