Skip to content

Instantly share code, notes, and snippets.

@AsishP
Last active October 3, 2018 10:50
Show Gist options
  • Save AsishP/583261bf9ef09eafce47e435c93cbf16 to your computer and use it in GitHub Desktop.
Save AsishP/583261bf9ef09eafce47e435c93cbf16 to your computer and use it in GitHub Desktop.
## Create an Encrypted Password ##
$AESKey = New-Object Byte[] 32
[Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($AESKey)
Set-Content C:\Temp\<PasswordFileName>.key $AESKey
## Run the above code first, then upload the above file to the Function App##
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
}
Get-EncryptedPassword -KeyPath C:\Temp\<PasswordFileName>.key -Password <Password>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment