Public/New-SecretSharingSecret.ps1
|
function New-SecretSharingSecret { <# .SYNOPSIS Generates a new random master secret for Shamir secret sharing. .DESCRIPTION Returns a cryptographically random secret of the requested entropy, as a SecureString, suitable as input to Split-SecretSharingSecret. Per SLIP-0039, the only valid entropy values are 128 and 256 bits. .PARAMETER Entropy The entropy of the generated secret, in bits. Must be 128 or 256. .EXAMPLE PS> $secret = New-SecretSharingSecret -Entropy 128 Generates a new 128-bit secret. .OUTPUTS System.Security.SecureString #> [CmdletBinding()] [OutputType([System.Security.SecureString])] [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSUseShouldProcessForStateChangingFunctions', '', Justification = 'Pure in-memory computation (random bytes); no external state is changed.')] param( [Parameter(Mandatory)] [ValidateSet(128, 256)] [int]$Entropy ) $secretByte = Get-SecretSharingRandomByte -Length ($Entropy / 8) return ConvertTo-SecretSharingSecureString -Byte $secretByte } |