9
3

Crypto.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef _CRYPTO_H
  17. #define _CRYPTO_H
  18. #include <string>
  19. #include <mutex>
  20. #include "RC4.h"
  21. #include "../common/types.h"
  22. using namespace std;
  23. class Crypto {
  24. public:
  25. ~Crypto(){ safe_delete(client); safe_delete(server); }
  26. Crypto() { rc4_key = 0; encrypted = false; client = 0; server = 0; };
  27. static int64 RSADecrypt(uchar* text, int16 size);
  28. void RC4Encrypt(uchar* text, int32 size);
  29. void RC4Decrypt(uchar* text, int32 size);
  30. int64 getRC4Key() { return rc4_key; }
  31. void setRC4Key(int64 key) {
  32. rc4_key = key;
  33. if(key > 0){
  34. encrypted = true;
  35. client = new RC4(~key);
  36. server = new RC4(key);
  37. uchar temp[20];
  38. client->Cypher(temp, 20);
  39. server->Cypher(temp, 20);
  40. }
  41. else{
  42. encrypted = false;
  43. safe_delete(client);
  44. safe_delete(server);
  45. }
  46. }
  47. bool isEncrypted(){ return encrypted; }
  48. void setEncrypted(bool in_val){ encrypted = in_val; }
  49. private:
  50. RC4* server;
  51. RC4* client;
  52. bool encrypted;
  53. int64 rc4_key;
  54. mutex MCrypto;
  55. };
  56. #endif