Skip to content

Instantly share code, notes, and snippets.

@dindoliboon
dindoliboon / aes_example.ps1
Last active August 12, 2020 22:43
Encrypt and decrypt with PowerShell
function Get-PlaintextFromSecureString([SecureString]$SecureString) {
return (New-Object -TypeName System.Net.NetworkCredential('fake-user', $SecureString, 'fake-domain')).Password
}
function EncryptStringToBytes([String]$Plaintext, [System.Security.SecureString]$Password) {
# C# code from:
# https://gist.github.com/mark-adams/87aa34da3a5ed48ed0c7
# https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.aes?view=netframework-4.8
$Aes = $null