Last active
September 12, 2023 17:15
-
-
Save maravedi/fd0259771a78cba7fee154b46bfdae50 to your computer and use it in GitHub Desktop.
Create an AES Key with PowerShell
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 New-AesKey { | |
Param( | |
[Int]$KeySize = 256, | |
[Switch]$AsString | |
) | |
$aesManaged = New-Object "System.Security.Cryptography.AesManaged" | |
$aesManaged.KeySize = $KeySize | |
$aesManaged.GenerateKey() | |
If($AsString) { | |
Return [System.Convert]::ToBase64String($aesManaged.Key) | |
} Else { | |
Return $AESManaged.Key | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment