Public/ConvertTo-SecretKey.ps1

<#
 
# ConvertTo-SecretKey
 
Ohne Beschreibung
 
- **Hashtags** UserCmdlet
- **Version** 2019.09.09
 
#>

# ? TITEL
# ? DESCRIPTION
# ? TAGS
# ? VERSION

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
}