blob: ae83792bded488e58b13e69b2ec0f83716d8244b [file] [log] [blame]
#include "aos/sha256.h"
#include <iomanip>
#include <sstream>
#include <string>
#include "absl/types/span.h"
#include "openssl/sha.h"
namespace aos {
std::string Sha256(const absl::Span<const uint8_t> str) {
unsigned char hash[SHA256_DIGEST_LENGTH];
SHA256_CTX sha256;
SHA256_Init(&sha256);
SHA256_Update(&sha256, str.data(), str.size());
SHA256_Final(hash, &sha256);
std::stringstream ss;
for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) {
ss << std::hex << std::setw(2) << std::setfill('0')
<< static_cast<int>(hash[i]);
}
return ss.str();
}
} // namespace aos