16 lines
709 B
PowerShell

# Compute the admin password, based on the DMP (digest master password).
# The Administrator password formula: BASE64 (HMAC-SHA256 (DMP, realm-value, username)).
function ComputeAdminPassword($hostName, $dmp)
{
$realm = GetDigestRealm $hostName $false
# Compute the hash.
$data = [Convert]::FromBase64String($dmp)
# Create HMAC-SHA256 service using the dmp as the key.
$sha = new-Object System.Security.Cryptography.HMACSHA256
$sha.Key = $data
$hashString = $realm + "admin"
# Compute the hash using the hash string.
$hash = $sha.ComputeHash([System.Text.Encoding]::ASCII.GetBytes($hashString))
$adminPassword = [Convert]::ToBase64String($hash)
return $adminPassword.ToUpper()
}