MyBase64.h 1.2 KB

123456789101112131415161718192021222324252627282930
  1. #include <string>
  2. using namespace std;
  3. namespace MyBase64{
  4. const unsigned char bad = 0xFF;
  5. const unsigned char base64Encode[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
  6. 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
  7. 'U', 'V', 'W', 'X', 'Y', 'Z',
  8. 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  9. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
  10. 'u', 'v', 'w', 'x', 'y', 'z',
  11. '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  12. '+', '/'
  13. };
  14. const unsigned char base64Decode[] = { 62, bad, bad, bad, 63, // + starts at 0x2B
  15. 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
  16. bad, bad, bad, bad, bad, bad, bad,
  17. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
  18. 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
  19. 20, 21, 22, 23, 24, 25,
  20. bad, bad, bad, bad, bad, bad,
  21. 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
  22. 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
  23. 46, 47, 48, 49, 50, 51
  24. };
  25. const unsigned char pad = '=';
  26. const int pemLineSz = 64;
  27. void Encode(const string plain,string& encoded);
  28. void Decode(const string coded,string& decoded);
  29. }