Commit c343b242 by Paweł Wegner

ICrypto: added hmac_sha1.

parent df4ca75d
......@@ -54,6 +54,14 @@ class ICrypto {
*/
virtual std::string hmac_sha256(const std::string& key,
const std::string& message) = 0;
/**
* Computes HMAC-SHA1
* @param key
* @param message
* @return HMAC-SHA1 hash
*/
virtual std::string hmac_sha1(const std::string& key,
const std::string& message) = 0;
/**
* Converts hash to hex string.
......
......@@ -51,6 +51,18 @@ std::string CryptoPP::hmac_sha256(const std::string& key,
return result;
}
std::string CryptoPP::hmac_sha1(const std::string& key,
const std::string& message) {
std::string mac;
::CryptoPP::HMAC<::CryptoPP::SHA1> hmac((byte*)key.c_str(), key.length());
::CryptoPP::StringSource(
message, true,
new ::CryptoPP::HashFilter(hmac, new ::CryptoPP::StringSink(mac)));
std::string result;
::CryptoPP::StringSource(mac, true, new ::CryptoPP::StringSink(result));
return result;
}
std::string CryptoPP::hex(const std::string& hash) {
std::string result;
::CryptoPP::StringSource(
......
......@@ -33,6 +33,8 @@ class CryptoPP : public ICrypto {
std::string sha256(const std::string& message) override;
std::string hmac_sha256(const std::string& key,
const std::string& message) override;
std::string hmac_sha1(const std::string& key,
const std::string& message) override;
std::string hex(const std::string& hash) override;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment