https://github.com/ismaelsadeeq/crypto-utils
https://github.com/ismaelsadeeq/crypto-utils
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/ismaelsadeeq/crypto-utils
- Owner: ismaelsadeeq
- Created: 2025-02-20T15:05:33.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-20T15:27:18.000Z (over 1 year ago)
- Last Synced: 2025-02-20T16:28:42.227Z (over 1 year ago)
- Language: C++
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
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);
```