Last active
August 7, 2024 10:35
-
-
Save lennybacon/9fcce97f84d1b760e8da0e9d0738536a to your computer and use it in GitHub Desktop.
Generate a new AES 256 Key with PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$random = [System.Security.Cryptography.RandomNumberGenerator]::Create(); | |
$buffer = New-Object byte[] 32; | |
$random.GetBytes($buffer); | |
[BitConverter]::ToString($buffer).Replace("-", [string]::Empty); |
What should I do if I need several AES 256 keys at once? Thks!
What should I do if I need several AES 256 keys at once? Thks!
Put it in a for-Loop?
$random = [System.Security.Cryptography.RandomNumberGenerator]::Create();
for($i=0; $i -lt 10; $i++){
$buffer = New-Object byte[] 32;
$random.GetBytes($buffer);
$key = [BitConverter]::ToString($buffer).Replace("-", [string]::Empty);
Write-Host "Key $($i): $($key)"
}
What should I do if I need several AES 256 keys at once? Thks!
Put it in a for-Loop?
$random = [System.Security.Cryptography.RandomNumberGenerator]::Create(); for($i=0; $i -lt 10; $i++){ $buffer = New-Object byte[] 32; $random.GetBytes($buffer); $key = [BitConverter]::ToString($buffer).Replace("-", [string]::Empty); Write-Host "Key $($i): $($key)" }
Thanks a lot!!!
Can you make a script that would add special characters in the key?
Can you make a script that would add special characters in the key?
The output is the Hexadecimal representation of the key - by definition this is only 0-9 and a-f. Special characters are encoded in the same way.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@lennybacon I added the some steps to run the above scripts for various OS:
Windows:
MacOS:
Linux: