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 918 B

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