Last active
May 5, 2020 04:13
-
-
Save dgosbell/8f2ed3a4908aeee34e3e02044e59a46a to your computer and use it in GitHub Desktop.
Generates a machineKey element for Power BI Report Server. Goes under <Configuration> element in rsreportserver.config file when you have an NLB setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generates a <machineKey> element that can be copied + pasted into a rsReportServer.config file for PowerBI Report Server | |
function Generate-MachineKey { | |
[CmdletBinding()] | |
param ( | |
[ValidateSet("AES", "DES", "3DES")] | |
[string]$decryptionAlgorithm = 'AES', | |
[ValidateSet("MD5", "SHA1", "HMACSHA256", "HMACSHA384", "HMACSHA512","AES")] | |
[string]$validationAlgorithm = 'AES' #'HMACSHA256' | |
) | |
process { | |
function BinaryToHex { | |
[CmdLetBinding()] | |
param($bytes) | |
process { | |
$builder = new-object System.Text.StringBuilder | |
foreach ($b in $bytes) { | |
$builder = $builder.AppendFormat([System.Globalization.CultureInfo]::InvariantCulture, "{0:X2}", $b) | |
} | |
$builder | |
} | |
} | |
switch ($decryptionAlgorithm) { | |
"AES" { $decryptionObject = new-object System.Security.Cryptography.AesCryptoServiceProvider } | |
"DES" { $decryptionObject = new-object System.Security.Cryptography.DESCryptoServiceProvider } | |
"3DES" { $decryptionObject = new-object System.Security.Cryptography.TripleDESCryptoServiceProvider } | |
} | |
$decryptionObject.GenerateKey() | |
$decryptionKey = BinaryToHex($decryptionObject.Key) | |
$decryptionObject.Dispose() | |
switch ($validationAlgorithm) { | |
"AES" { $validationObject = new-object System.Security.Cryptography.AesCryptoServiceProvider } | |
"MD5" { $validationObject = new-object System.Security.Cryptography.HMACMD5 } | |
"SHA1" { $validationObject = new-object System.Security.Cryptography.HMACSHA1 } | |
"HMACSHA256" { $validationObject = new-object System.Security.Cryptography.HMACSHA256 } | |
"HMACSHA385" { $validationObject = new-object System.Security.Cryptography.HMACSHA384 } | |
"HMACSHA512" { $validationObject = new-object System.Security.Cryptography.HMACSHA512 } | |
} | |
$validationKey = BinaryToHex($validationObject.Key) | |
$validationObject.Dispose() | |
[string]::Format([System.Globalization.CultureInfo]::InvariantCulture, | |
"<machineKey decryption=`"{0}`" decryptionKey=`"{1}`" validation=`"{2}`" validationKey=`"{3}`" />", | |
$decryptionAlgorithm.ToUpperInvariant(), $decryptionKey, | |
$validationAlgorithm.ToUpperInvariant(), $validationKey) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment