Created
April 18, 2017 03:12
-
-
Save BrandonStiff/02cada362bfca007d298b549506f225f to your computer and use it in GitHub Desktop.
Get Encryption Key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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