You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**`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).
4
4
5
5
## Features
6
+
6
7
- 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.
8
12
9
13
## 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
+
11
19
```powershell
12
20
.\Get-RandomHex.ps1
13
21
```
@@ -17,10 +25,33 @@ To generate a hex string in PowerShell based on a desired bit length:
17
25
.\Get-RandomHex.ps1 -BitLength 128
18
26
```
19
27
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
+
20
44
## 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
+
```
24
55
25
56
## 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