powershell encrypt password code example

Example 1: password encryptin powershell

(get-credential).Password | ConvertFrom-SecureString -key (get-content C:\passwords\aes.key) | set-content "C:\Passwords\password.txt"

Example 2: powershell password encryption in script

(get-credential).password | ConvertFrom-SecureString | set-content "C:\Passwords\password.txt"

Example 3: password encryptin powershell

$password = Get-Content C:\Passwords\password.txt | ConvertTo-SecureString -Key (Get-Content C:\Passwords\aes.key)
$credential = New-Object System.Management.Automation.PsCredential("Luke",$password)

Example 4: password encryptin powershell

$Key = New-Object Byte[] 32
[Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($Key)
$Key | out-file C:\passwords\aes.key