Forked from kennwhite/powershell_command_urandom.js
Created
December 10, 2020 20:50
-
-
Save marcoonroad/374328e68407dd46b0411e43a26e70f4 to your computer and use it in GitHub Desktop.
Powershell 1-liner to generate random n-byte key from Windows command line
This file contains hidden or 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
// Windows equivalent to Linux/Mac: echo $(head -c 64 /dev/urandom | base64 | tr -d '\n') | |
// Get-Random in Windows 10/Server 2016 PowerShell uses a CSPRNG seed by default. | |
// Prior to PS 5.1, seed was system clock. | |
// For Win 10/2016+ | |
powershell -command "[Convert]::ToBase64String((1..64|%{[byte](Get-Random -Max 256)}))" | |
// For Win 8.x/2012 | |
powershell -command "$r=[byte[]]::new(64);$g=[System.Security.Cryptography.RandomNumberGenerator]::Create();$g.GetBytes($r);[Convert]::ToBase64String($r)" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment