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.

main.cpp 1.5 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include <cstdlib>
  2. #include <cstdio>
  3. #include <iostream>
  4. #include <vector>
  5. // #include "lane_fitter_least_square.h"
  6. extern "C" {
  7. #include "base64.h"
  8. // #include "aes.h"
  9. #include "aes_util.h"
  10. #include "sha.h"
  11. }
  12. static void _encode(const void * buffer, size_t bufferSize, void ** output, size_t * outputSize)
  13. {
  14. char * tmpBuffer = NULL;
  15. size_t size = 0;
  16. size_t tmpOutputSize = Base64_GetCodeLength(bufferSize);
  17. tmpBuffer = (char *)malloc(tmpOutputSize + 1);
  18. size = Base64_Encode((const char *)buffer, bufferSize, tmpBuffer);
  19. tmpBuffer[size] = 0;
  20. *output = tmpBuffer;
  21. *outputSize = size;
  22. }
  23. static void _decode(const std::vector<char>& buffer, std::vector<char>& output)
  24. {
  25. output.resize(Base64_GetDataLength(buffer.size()));
  26. size_t size = Base64_Decode(&buffer[0], buffer.size(), &output[0]);
  27. output.resize(size);
  28. }
  29. int main()
  30. {
  31. unsigned char in[] = "test key";
  32. unsigned char key[32];
  33. memset(key, 0, 32);
  34. sha256(in, strlen((const char *)in), key);
  35. printf("sha256\n");
  36. for(int i = 0; i < 32; i++)
  37. {
  38. printf("%x", key[i]);
  39. }
  40. std::cout << std::endl;
  41. char *output;
  42. size_t outputSize;
  43. std::vector<char> enc;
  44. std::vector<char> out;
  45. const char *encrypt = "P37w+VZImNgPEO1RBhJ6RtKl7n6zymIbEG1pReEzghk=";
  46. enc.assign(encrypt, encrypt + strlen(encrypt));
  47. _decode(enc, out);
  48. printf("base64 decode\n");
  49. std::cout << encrypt << std::endl;
  50. for(auto c : out)
  51. {
  52. printf("%x", c);
  53. }
  54. std::cout << std::endl;
  55. return 0;
  56. }