Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get Encryption Key
function Get-EncryptionKey()
{
<#
.SYNOPSIS
Retrieves a 128/192/256-bit encryption key using the given keyphrase.
.PARAMETER KeyPhrase
Specifies the phrase to use to create the 128-bit key.
.PARAMETER Length
Specifies the number of bits to make the length. Use either 128, 192, or 256 bits. Default is 128.
.OUTPUTS
[byte[]]
Returns a 128/192/256-bit (32/48/64-byte) array that represents the keyphrase.
#>
[CmdletBinding()]
param
(
[Parameter(Mandatory=$true,Position=0,ValueFromPipeline=$true)]
[string] $KeyPhrase,
[ValidateSet(128,192,256)] [int] $Length = 128
)
process
{
$enc = [System.Text.Encoding]::UTF8;
$bytes = $Length / 4;
$KeyPhrase = $KeyPhrase.PadRight($bytes, "0").SubString(0,$bytes);
$enc.GetBytes($KeyPhrase);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.