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.1 kB

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
9 years ago
10 years ago
12345678910111213141516171819202122232425262728293031323334353637
  1. using System.Security.Cryptography;
  2. using System.Text;
  3. namespace Shadowsocks.Encryption
  4. {
  5. public abstract class EncryptorBase
  6. : IEncryptor
  7. {
  8. public const int MAX_INPUT_SIZE = 32768;
  9. protected EncryptorBase(string method, string password, bool onetimeauth, bool isudp)
  10. {
  11. Method = method;
  12. Password = password;
  13. OnetimeAuth = onetimeauth;
  14. IsUDP = isudp;
  15. }
  16. protected string Method;
  17. protected string Password;
  18. protected bool OnetimeAuth;
  19. protected bool IsUDP;
  20. protected byte[] GetPasswordHash()
  21. {
  22. byte[] inputBytes = Encoding.UTF8.GetBytes(Password);
  23. byte[] hash = MD5.Create().ComputeHash(inputBytes);
  24. return hash;
  25. }
  26. public abstract void Encrypt(byte[] buf, int length, byte[] outbuf, out int outlength);
  27. public abstract void Decrypt(byte[] buf, int length, byte[] outbuf, out int outlength);
  28. public abstract void Dispose();
  29. }
  30. }