Public/ConvertTo-EncryptedData.ps1

<#
 
# ConvertTo-EncryptedData
 
Ohne Beschreibung
 
- **Hashtags** UserCmdlet
- **Version** 2019.01.01
 
#>

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

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

Function ConvertTo-EncryptedData {
    Param (
        [Byte[]]$Key,

        [string]$TextInput
    )
    
    #Create a new secure string object.
    $SecureString = New-Object System.Security.SecureString;

    #Convert the text input to a char array.
    $Chars = $TextInput.ToCharArray();
    
    #Foreach char in the array.
    ForEach($Char in $Chars) {
        #Append the char to the secure string.
        $SecureString.AppendChar($Char);
    }
    
    #Encrypt the data from the secure string.
    $EncryptedData = ConvertFrom-SecureString -SecureString $SecureString -Key $Key;

    #Return the encrypted data.
    Return $EncryptedData;
}