2018-11-07 21:26:32 +01:00
|
|
|
/*
|
|
|
|
* IXHMac.h
|
|
|
|
* Author: Benjamin Sergeant
|
|
|
|
* Copyright (c) 2018 Machine Zone. All rights reserved.
|
|
|
|
*/
|
|
|
|
#include "IXHMac.h"
|
2018-11-13 02:56:59 +01:00
|
|
|
#include "IXBase64.h"
|
2018-11-07 21:26:32 +01:00
|
|
|
|
|
|
|
#include <openssl/hmac.h>
|
|
|
|
|
|
|
|
namespace ix
|
|
|
|
{
|
|
|
|
std::string hmac(const std::string& data, const std::string& key)
|
|
|
|
{
|
|
|
|
constexpr size_t hashSize = 16;
|
|
|
|
unsigned char hash[hashSize];
|
|
|
|
|
|
|
|
HMAC(EVP_md5(),
|
|
|
|
key.c_str(), (int) key.size(),
|
|
|
|
(unsigned char *) data.c_str(), (int) data.size(),
|
|
|
|
(unsigned char *) hash, nullptr);
|
|
|
|
|
|
|
|
std::string hashString(reinterpret_cast<char*>(hash), hashSize);
|
|
|
|
|
|
|
|
return base64_encode(hashString, (uint32_t) hashString.size());
|
|
|
|
}
|
|
|
|
}
|