Encrypt password with key using PowerShell
Scenario:
Encrypt password with key using PowerShell.
One major issue that I had to overcome, was to hide the password for the scripts that I will use them on schedule and there will be no need to include it as clear text. Using the below I was able to encrypt the password of the user that I will use in a script and retrieve it within the script whenever is needed. The below method encrypts the password using a 256-bit AES encryption key, which is consider from 32 x 8-bit integers. The numbers that you can use are from 0 to 255.
Related Links:
- PowerShell Scripts
- PowerShell Tutorials
- Using the Read-Host Cmdlet – TechNet – Microsoft
- ConvertFrom-SecureString – Microsoft Docs
- Using the Out-File Cmdlet – TechNet – Microsoft
Solution / Script:
$File = "C:\Scripts\Password.txt"
$Key = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32)
$Password = Read-Host -AsSecureString "Enter the password"
$Password | ConvertFrom-SecureString -Key $key | Out-File $file


[…] Encrypt Password with key using PowerShell […]