Last active
May 30, 2023 08:17
-
-
Save jetersen/0ac37e3f684947889d53cccb7391a9c5 to your computer and use it in GitHub Desktop.
Enable TLS 1.2 for .NET application including Windows PowerShell and .NET 45 and below
This file contains 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
#requires -runasadministrator | |
# set strong cryptography on 64 bit .Net Framework | |
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v2.0.50727' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord | |
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord | |
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v2.0.50727' -Name 'SystemDefaultTlsVersions' -Value '1' -Type DWord | |
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SystemDefaultTlsVersions' -Value '1' -Type DWord | |
# set strong cryptography on 32 bit .Net Framework | |
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NETFramework\v2.0.50727' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord | |
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord | |
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NETFramework\v2.0.50727' -Name 'SystemDefaultTlsVersions' -Value '1' -Type DWord | |
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SystemDefaultTlsVersions' -Value '1' -Type DWord |
This file contains 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
#requires -runasadministrator | |
# revert strong cryptography on 64 bit .Net Framework | |
Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v2.0.50727' -Name 'SchUseStrongCrypto' | |
Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' | |
Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v2.0.50727' -Name 'SystemDefaultTlsVersions' | |
Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SystemDefaultTlsVersions' | |
# revert strong cryptography on 32 bit .Net Framework | |
Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NETFramework\v2.0.50727' -Name 'SchUseStrongCrypto' | |
Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' | |
Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NETFramework\v2.0.50727' -Name 'SystemDefaultTlsVersions' | |
Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SystemDefaultTlsVersions' |
Here is an array version of it:
$properties = @{
'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v2.0.50727' = @('SchUseStrongCrypto', 'SystemDefaultTlsVersions')
'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' = @('SchUseStrongCrypto', 'SystemDefaultTlsVersions')
'HKLM:\SOFTWARE\Microsoft\.NETFramework\v2.0.50727' = @('SchUseStrongCrypto', 'SystemDefaultTlsVersions')
'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' = @('SchUseStrongCrypto', 'SystemDefaultTlsVersions')
}
foreach ($property in $properties.GetEnumerator()) {
$path = $property.Key
$names = $property.Value
foreach ($name in $names) {
Set-ItemProperty -Path $path -Name $name -Value 1 -ErrorAction SilentlyContinue
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on this info: https://docs.microsoft.com/en-us/dotnet/framework/network-programming/tls#configuring-security-via-the-windows-registry