Skip to content

Instantly share code, notes, and snippets.

@darrenjrobinson
Created January 4, 2017 23:46
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 darrenjrobinson/07c9526694ab2a0fea56edfec77496df to your computer and use it in GitHub Desktop.
Save darrenjrobinson/07c9526694ab2a0fea56edfec77496df to your computer and use it in GitHub Desktop.
$AESKey = New-Object Byte[] 32
[Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($AESKey)
# file to output the encrypted key too
Set-Content C:\Temp\AzureAutomationPassKey.key $AESKey
Function Get-EncryptedPassword
{
param (
[Parameter(Mandatory=$true,HelpMessage='Please specify the key file path')][ValidateScript({Test-Path $_})][String]$KeyPath,
[Parameter(Mandatory=$true,HelpMessage='Please specify password in clear text')][ValidateNotNullOrEmpty()][String]$Password
)
$secPw = ConvertTo-SecureString -AsPlainText $Password -Force
$AESKey = Get-content $KeyPath
$Encryptedpassword = $secPw | ConvertFrom-SecureString -Key $AESKey
$Encryptedpassword
}
$encryptedpass = Get-EncryptedPassword -KeyPath C:\temp\AzureAutomationPassKey.key -Password "thisisntmypassword!"
# Get the encryption string and copy to the clipboard for use in app config
$encryptedpass | clip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment