Cmdlets/ConvertTo-EncryptedData.ps1
# ? TITEL ConvertTo-EncryptedData # ? DESCRIPTION # ? TAGS UserCmdlet # ? VERSION 2019.01.01 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-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; } |