Private/SecureString/ConvertTo-SecretSharingSecureString.ps1

function ConvertTo-SecretSharingSecureString {
    <#
    .SYNOPSIS
        Wraps an arbitrary byte array in a SecureString, one byte per character.
    .DESCRIPTION
        SecureString is designed for text, not arbitrary binary data, but the
        project's signed-off design keeps the secret's bytes in a SecureString at the
        New-/Join-SecretSharingSecret cmdlet boundary. Each byte (0-255) becomes one
        UTF-16 character with that exact code point - safely representable as a single
        code unit, since 0-255 falls well below the surrogate range - so
        ConvertFrom-SecretSharingSecureString can recover the exact original bytes.
        This is not text encoding and must not be used for the -Passphrase parameter,
        which is real user-typed text - see ConvertFrom-SecretSharingPassphraseSecureString.
    #>

    [CmdletBinding()]
    [OutputType([System.Security.SecureString])]
    param(
        [Parameter(Mandatory)]
        [byte[]]$Byte
    )

    $secureString = New-Object System.Security.SecureString
    foreach ($b in $Byte) {
        $secureString.AppendChar([char]$b)
    }
    $secureString.MakeReadOnly()

    return $secureString
}