OAuthKey.cpp 668 B

12345678910111213141516171819202122232425262728293031
  1. #include "OAuthKey.h"
  2. #include "b64.h"
  3. OAuthKey::OAuthKey(const void *key, size_t key_len)
  4. {
  5. HMAC_SHA256_Init(&ctx);
  6. HMAC_SHA256_UpdateKey(&ctx, (unsigned char *)key, (int)key_len);
  7. HMAC_SHA256_EndKey(&ctx);
  8. HMAC_SHA256_StartMessage(&ctx);
  9. }
  10. OAuthKey::~OAuthKey()
  11. {
  12. HMAC_SHA256_Done(&ctx);
  13. }
  14. void OAuthKey::FeedMessage(const void *data, size_t data_len)
  15. {
  16. HMAC_SHA256_UpdateMessage(&ctx, (unsigned char *)data, (unsigned int)data_len);
  17. }
  18. void OAuthKey::EndMessage()
  19. {
  20. HMAC_SHA256_EndMessage(buf, &ctx);
  21. }
  22. void OAuthKey::GetBase64(char *output, size_t cch)
  23. {
  24. size_t len = b64::b64_encode(buf, HMAC_SHA256_DIGEST_LENGTH, output, cch);
  25. output[len] = '\0';
  26. }