AipApiManager.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include "pch.h"
  2. #include "AipApiManager.h"
  3. #include "TWinCryptF.h"
  4. #include <iostream>
  5. #include <string>
  6. #include <fstream>
  7. #include <sstream>
  8. #include <vector>
  9. #include <map>
  10. #include <algorithm>
  11. #include <functional>
  12. #include <cctype>
  13. #include <locale>
  14. #include <ctime>
  15. using namespace std;
  16. extern "C" {
  17. // SHA-256 ÇØ½Ã¸¦ »ý¼ºÇÏ´Â ÇÔ¼ö
  18. AIPAPIMANAGER_API std::string __stdcall AipApiEncrpyt(const char* AEncMessage)
  19. {
  20. try
  21. {
  22. TWinCrypt crypt;
  23. std::string sEncrypted = crypt.EncryptStrToHex(AEncMessage);
  24. return sEncrypted;
  25. }
  26. catch (const std::exception& ex)
  27. {
  28. std::string errorMessage = ex.what();
  29. return "";
  30. }
  31. }
  32. AIPAPIMANAGER_API int __stdcall AipApiDecrypt(const char* ADecMessage, char* AEncMessage)
  33. {
  34. try
  35. {
  36. TWinCrypt crypt;
  37. //std::cout << "ADecMessage message: " << ADecMessage << std::endl;
  38. std::string sDecrypted = crypt.DecryptStrFromHex(ADecMessage);
  39. //std::cout << "sDecrypted message: " << sDecrypted << std::endl;
  40. strcpy(AEncMessage, sDecrypted.c_str());
  41. return 0;
  42. }
  43. catch (const std::exception& ex)
  44. {
  45. std::string errorMessage = ex.what();
  46. return -1;
  47. }
  48. }
  49. AIPAPIMANAGER_API std::string __stdcall AipApiDecrypt2(const char* ADecMessage)
  50. {
  51. try
  52. {
  53. TWinCrypt crypt;
  54. std::string sDecrypted = crypt.DecryptStrFromHex(ADecMessage);
  55. return sDecrypted;
  56. }
  57. catch (const std::exception& ex)
  58. {
  59. std::string errorMessage = ex.what();
  60. return "";
  61. }
  62. }
  63. }