Войти

Показать полную графическую версию : [решено] Инкремент


Страниц : 1 [2]

Kazun
03-05-2016, 13:14
Самое простое использовать ConvertTo-SecureString/ConvertFrom-SecureString с параметром Key:

#Генерируем ключ
$KeyFile = "\\Server\Share\Key.txt"
$Key = New-Object Byte[] 32
[Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($Key)
$Key | Out-File $KeyFile
В примере ключ сохранен в файл на шаре, можно его записать в таблицу SQL.

#Шифруем пароль
$PasswordFile = "\\Server\Share\PAES.txt"
$KeyFile = "\\Server\Share\Key.txt"
$Key = Get-Content $KeyFile
$Password = 'P@$$w0rd' | ConvertTo-SecureString -AsPlainText -Force
$Password | ConvertFrom-SecureString -key $Key | Out-File $PasswordFile
В примере пароль сохранен в файл на шаре, можно его записать в таблицу SQL.

#Credentials
$UserName = "User"
$PasswordFile = "\\Server\Share\PAES.txt"
$KeyFile = "\\Server\Share\Key.txt"
$Key = Get-Content $KeyFile
$Password = Get-Content $PasswordFile | ConvertTo-SecureString -Key $Key
$Cred = New-Object Management.Automation.PSCredential($UserName, $Password)

И теперь можно подставлять в скрипте:
$Cred.UserName - Имя пользователя
$Cred.GetNetworkCredential().Password - Пароль

Securely Store Credentials on Disk (http://www.powershellcookbook.com/recipe/PukO/securely-store-credentials-on-disk)

PowerShell Encryption Examples (https://gallery.technet.microsoft.com/scriptcenter/PowerShell-Encryption-45709b87)
Share encrypted data between users and computers with PowerShell (https://gallery.technet.microsoft.com/Share-encrypted-data-2f91fd3f) - Использование сертификатов




© OSzone.net 2001-2012