9
3

Crypto.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 "RC4.h"
  20. #include "../common/types.h"
  21. using namespace std;
  22. class Crypto {
  23. public:
  24. ~Crypto(){ safe_delete(client); safe_delete(server); }
  25. Crypto() { rc4_key = 0; encrypted = false; client = 0; server = 0; };
  26. static int64 RSADecrypt(uchar* text, int16 size);
  27. void RC4Encrypt(uchar* text, int32 size);
  28. void RC4Decrypt(uchar* text, int32 size);
  29. int64 getRC4Key() { return rc4_key; }
  30. void setRC4Key(int64 key) {
  31. rc4_key = key;
  32. if(key > 0){
  33. encrypted = true;
  34. client = new RC4(~key);
  35. server = new RC4(key);
  36. uchar temp[20];
  37. client->Cypher(temp, 20);
  38. server->Cypher(temp, 20);
  39. }
  40. else{
  41. encrypted = false;
  42. safe_delete(client);
  43. safe_delete(server);
  44. }
  45. }
  46. bool isEncrypted(){ return encrypted; }
  47. void setEncrypted(bool in_val){ encrypted = in_val; }
  48. private:
  49. RC4* server;
  50. RC4* client;
  51. bool encrypted;
  52. int64 rc4_key;
  53. };
  54. #endif