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

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
1234567891011121314151617181920212223242526272829303132333435
  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)
  10. {
  11. Method = method;
  12. Password = password;
  13. OnetimeAuth = onetimeauth;
  14. }
  15. protected string Method;
  16. protected string Password;
  17. protected bool OnetimeAuth;
  18. protected byte[] GetPasswordHash()
  19. {
  20. byte[] inputBytes = Encoding.UTF8.GetBytes(Password);
  21. byte[] hash = MD5.Create().ComputeHash(inputBytes);
  22. return hash;
  23. }
  24. public abstract void Encrypt(byte[] buf, int length, byte[] outbuf, out int outlength);
  25. public abstract void Decrypt(byte[] buf, int length, byte[] outbuf, out int outlength);
  26. public abstract void Dispose();
  27. }
  28. }