Skip to content

Commit 80a321c

Browse files
authored
Update README.md
1 parent 8aeebd6 commit 80a321c

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

README.md

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
# Get-RandomHex
22

3-
**`Get-RandomHex.ps1`** is a PowerShell function designed to generate cryptographically secure random hexadecimal strings. A typical use case is the generation of a 16-byte (128-bit) key, which aligns with the recommended minimum entropy for session IDs [as per OWASP guidelines](https://www.owasp.org/index.php/Insufficient_Session-ID_Length).
3+
**`Get-RandomHex.ps1`** is a PowerShell script designed to generate cryptographically secure random hexadecimal strings. This is useful for creating keys, tokens, or any scenario where high-entropy random data is required. A common use case is generating a 16-byte (128-bit) key, which aligns with the recommended minimum entropy for session IDs [as per OWASP guidelines](https://owasp.org/www-community/vulnerabilities/Insufficient_Session-ID_Length).
44

55
## Features
6+
67
- Generates random hexadecimal strings based on a specified bit length.
7-
- Uses cryptographically secure random number generation.
8+
- Utilizes cryptographically secure random number generation methods.
9+
- Compatible with multiple .NET versions due to the use of `RandomNumberGenerator.Create()`.
10+
- Accepts the `-BitLength` parameter at both the script and function levels.
11+
- Handles bit lengths not divisible by 8 by appropriately trimming the output.
812

913
## Usage
10-
To generate a hex string in PowerShell without a desired bit length generates a key with the default bit length of 256:
14+
15+
### Running the Script Directly
16+
17+
To generate a hex string without specifying a bit length (defaults to 256 bits):
18+
1119
```powershell
1220
.\Get-RandomHex.ps1
1321
```
@@ -17,10 +25,33 @@ To generate a hex string in PowerShell based on a desired bit length:
1725
.\Get-RandomHex.ps1 -BitLength 128
1826
```
1927

28+
## Importing the Function into Your Session
29+
You can import the function and use it directly in your PowerShell session:
30+
31+
- Import the function
32+
```powershell
33+
. .\Get-RandomHex.ps1
34+
```
35+
- Generate a 256-bit random hexadecimal string
36+
```powershell
37+
Get-RandomHexString
38+
```
39+
- Generate a 128-bit random hexadecimal string
40+
```powershell
41+
Get-RandomHexString -BitLength 128
42+
```
43+
2044
## Installation
21-
1. Clone or download this repository.
22-
2. Import the provided `.ps1` script into your PowerShell session.
23-
3. Run **`Get-RandomHex.ps1`** script, optional with the desired bit length parameter.
45+
1. **Clone** or **download** this repository to your local machine.
46+
2. **Run the script directly** or **import the function** into your PowerShell session.
47+
- Running the script directly:
48+
```powershell
49+
.\Get-RandomHex.ps1
50+
```
51+
- Importing the function:
52+
```powershell
53+
. .\Get-RandomHex.ps1 # Note the dot and space before the script path
54+
```
2455
2556
## Contribution
26-
Pull requests and issues are welcome! Before submitting a PR, please ensure that you've run tests and added any necessary documentation.
57+
Contributions are welcome! Please open an issue or submit a pull request for any improvements or fixes. Before submitting a PR, ensure that you've tested your changes and updated any necessary documentation.

0 commit comments

Comments
 (0)