Private/Shamir/Get-SecretSharingRandomByte.ps1
|
function Get-SecretSharingRandomByte { <# .SYNOPSIS Returns a cryptographically random byte array of the requested length. .DESCRIPTION Backed by System.Security.Cryptography.RandomNumberGenerator, which is CSPRNG-backed and available identically on Windows PowerShell 5.1 and PowerShell Core. #> [CmdletBinding()] [OutputType([byte[]], [System.Object[]])] param( [Parameter(Mandatory)] [ValidateRange(1, [int]::MaxValue)] [int]$Length ) $bytes = [byte[]]::new($Length) $rng = [System.Security.Cryptography.RandomNumberGenerator]::Create() try { $rng.GetBytes($bytes) } finally { $rng.Dispose() } return , $bytes } |