in Powershell i use a script which create Users from a MySQL Database.
The only thing which doesn't work is the Password.
I Do the following:
Code: Select all
$ftp_password = [ Text.Encoding ]::UTF8.GetBytes( $brow .ftp_password.Trim ())
$iterations = 100000
# Erzeugen Sie das Salt
$salt = New-Object Byte[] 32
[ Security.Cryptography.RNGCryptoServiceProvider ]::Create().GetBytes( $salt )
# Dann können Sie die Funktionen verwenden, um das Salt und den Hash zu generieren
#Encryption
# Erzeugen eines Hashes mit PBKDF2
$rng = New-Object Security.Cryptography.Rfc2898DeriveBytes $ftp_password , $salt , 100000
$hash = $rng .GetBytes ( 32 )
# Zum Schluss können Sie das Salt und den Hash in Base64 konvertieren
$null = $saltBase64 = [ System.Convert ]::ToBase64String( $salt )
$null = $hashBase64 = [ System.Convert ]::ToBase64String( $hash )
$null = $hash = $xml .CreateElement ( "hash" )
$null = $hash .InnerText = $hashBase64
$null = $password .AppendChild ( $hash )
$null = $salt = $xml .CreateElement ( "salt" )
$null = $salt .InnerText = $saltbase64
$null = $password .AppendChild ( $salt )
$null = $iterationsxml = $xml .CreateElement ( "iterations" )
$null = $iterationsxml .InnerText = $iterations
$null = $password .AppendChild ( $iterationsxml )
$null = $newUser .AppendChild ( $password )
Thanx a lot