Skip to content

Instantly share code, notes, and snippets.

@Megabytemb
Forked from complex86/AES.ps1
Last active June 29, 2016 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Megabytemb/e8ed0609c4f65c25f3c8b68758b577fa to your computer and use it in GitHub Desktop.
Save Megabytemb/e8ed0609c4f65c25f3c8b68758b577fa to your computer and use it in GitHub Desktop.
#AES Key file export location
$KeyFile = "C:\AES.key"
#Generate Key
$Key = New-Object Byte[] 16 # You can use 16, 24, or 32 for AES
[Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($Key)
#write key to file
$Key | out-file $KeyFile
$PasswordFile = "C:\Encrypted_Password.txt"
$password = Get-Content $PasswordFile
$AESKeyFile = "C:\AES.key"
$AESKey = Get-Content $AESKeyFilePath
$securepassword = $password | ConvertTo-SecureString -key $AESKey
$username = "Admin User"
$credential = New-Object System.Management.Automation.PSCredential($username,$securepassword)
$job = Start-Job -scriptblock {
$domain = "domain_name"
$ADCreds = Get-Credential -Message "Enter your AD Username and Password"
Add-Computer -DomainName $domain -Credential $ADCreds
} -Args $target -credential $credential
#Load AES Key
$KeyFile = "C:\AES.key"
$Key = Get-Content $KeyFile
#Set Export file
$PasswordFile = "C:\Encrypted_Password.txt"
#Encrypt "My Password"
$Password = "my_password" | ConvertTo-SecureString -AsPlainText -Force
#Save to Disk
$Password | ConvertFrom-SecureString -key $Key | Out-File $PasswordFile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment