Added Crypto::pbkdf2

This commit is contained in:
eidheim 2016-12-20 16:17:00 +01:00
commit 9e29d2d572
2 changed files with 15 additions and 8 deletions

View file

@ -133,6 +133,18 @@ namespace SimpleWeb {
return hash;
}
/// Returns empty string on error. key_size is in bytes.
static std::string pbkdf2(const std::string &password, const std::string &salt, int iterations = 4096, int key_size = 256 / 8) {
std::string key;
key.resize(key_size);
auto success = PKCS5_PBKDF2_HMAC_SHA1(password.c_str(), password.size(),
reinterpret_cast<const unsigned char*>(salt.c_str()), salt.size(), iterations,
key_size, reinterpret_cast<unsigned char*>(&key[0]));
if (!success)
return std::string();
return key;
}
};
}
#endif /* CRYPTO_HPP */