Cmdlets/ConvertTo-SecretKey.ps1

# ? TITEL ConvertTo-SecretKey
# ? DESCRIPTION
# ? TAGS UserCmdlet
# ? VERSION 2019.09.09

using Module Microsoft.PowerShell.Management
using Module Microsoft.PowerShell.Utility
using namespace System
using namespace System.Runtime.InteropServices
$ErrorActionPreference = [System.Management.Automation.ActionPreference]::Stop
Set-StrictMode -Version Latest

Function ConvertTo-SecretKey {
    Param (
        [Parameter(Mandatory = $true)]
        [ValidateLength(16, 32)]
        [string]$Key
    )
 
    $pad = 32 - $Key.Length
    $encoding = New-Object -TypeName System.Text.ASCIIEncoding
    $bytes = $Encoding.GetBytes($Key + "0" * $Pad)
    
    Return $Bytes
}