This file includes the function GenerateCryptographicallySecureRandomNumber, which generates random bytes.
Currently supported platforms are Linux and Apple. The entropy level of this random bytes depends on the machine; if the machine has high entropy, the generated bytes will also have high entropy.
The method uses /dev/urandom which is assumed to be cryptographically secure.
To use this function, include crypto-utils/random.h.
#include "crypto-utils/random.h"
size_t num_bytes = 16;
std::vector<unsigned char> random_bytes = GenerateCryptographicallySecureRandomNumber(num_bytes);The function GenerateCryptographicallySecureRandomNumber takes a single parameter of type size_t, which specifies the number of random bytes to generate.
It returns a std::vector<unsigned char> containing the generated random bytes as elements in the vector.
This file contains two functions:
to_hex: Takes astd::vector<unsigned char>and returns its hexadecimal string representation.from_hex: Takes a hexadecimal string and converts it into astd::vector<unsigned char>.
To use these functions, include crypto-utils/hex.h.
#include "crypto-utils/hex.h"
std::string msg("hi");
std::vector<unsigned char> data(msg.begin(), message.end());
std::string hex_string = to_hex(data);
std::vector<unsigned char> decoded_data = from_hex(hex_string);