Skip to content

Instantly share code, notes, and snippets.

@maravedi
Last active September 12, 2023 17:15
Show Gist options
  • Save maravedi/fd0259771a78cba7fee154b46bfdae50 to your computer and use it in GitHub Desktop.
Save maravedi/fd0259771a78cba7fee154b46bfdae50 to your computer and use it in GitHub Desktop.
Create an AES Key with PowerShell
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