22 std::vector<unsigned char> bytes(num_bytes);
23 if (RAND_bytes(bytes.data(),
static_cast<int>(bytes.size())) != 1) {
24 throw std::runtime_error(
"RAND_bytes failed");
26 static const char hex[] =
"0123456789abcdef";
28 out.reserve(num_bytes * 2);
29 for (
unsigned char b : bytes) {
30 out.push_back(hex[b >> 4]);
31 out.push_back(hex[b & 0x0F]);