An open API service indexing awesome lists of open source software.

https://github.com/ismaelsadeeq/crypto-utils


https://github.com/ismaelsadeeq/crypto-utils

Last synced: over 1 year ago
JSON representation

Awesome Lists containing this project

README

          

### This repository contains cryptography utility functions.

#### **random.h**

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.

##### **Usage:**
To use this function, include `crypto-utils/random.h`.

```cpp
#include "crypto-utils/random.h"

size_t num_bytes = 16;
std::vector 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` containing the generated random bytes as elements in the vector.

---

### **hex.h**

This file contains two functions:

- `to_hex`: Takes a `std::vector` and returns its hexadecimal string representation.
- `from_hex`: Takes a hexadecimal string and converts it into a `std::vector`.

##### **Usage:**
To use these functions, include `crypto-utils/hex.h`.

```cpp
#include "crypto-utils/hex.h"

std::string msg("hi");
std::vector data(msg.begin(), message.end());
std::string hex_string = to_hex(data);

std::vector decoded_data = from_hex(hex_string);
```