Public/ConvertTo-Base64Secure.ps1

function ConvertTo-Base64Secure {
    <#
    .SYNOPSIS
        Encodes a string to a base64 string, then converts it to a secure string.
    .DESCRIPTION
        This function consumes a string, encodes it to a base64 string, and converts it to a
        secure string.
    .PARAMETER String
        The string to encode and convert.
    .INPUTS
        System.String[]
    .OUTPUTS
        System.String
    .EXAMPLE
        ConvertTo-Base64Secure -String 'Hello, world!'

        Consume a string, encode it, and convert it to a secure string.
    .NOTES
        None
    #>


    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0)]
        [string]$String
    )

    begin {}

    process {
        $string = 'Hello, world!'

        $stringBytes = [System.Text.Encoding]::UTF8.GetBytes($string)

        $encodedBytes = [System.Convert]::ToBase64String($stringBytes)
        $encodedBytes
    }

    end {}
}