Chris
Chris

Reputation: 743

Detecting if FIPS is being enforced via .NET C#

Is there a way to determine from the .NET framework whether or not the FIPS policy is being enforced on the windows computer?

Upvotes: 6

Views: 2084

Answers (2)

blueharoon
blueharoon

Reputation: 127

It has already been answered by @ta-speot-is in the comments, adding it as an answer if someone overlooks that comment.

To know if FIPS is enabled we can simply check the boolean flag CryptoConfig.AllowOnlyFipsAlgorithms available in .Net Framework 4.0 and higher versions.

Upvotes: 5

Gaurav
Gaurav

Reputation: 902

You can use this code to check whether FIPS is enabled or not:

public static object getKey(string Name)
{
    RegistryKey uac = Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\Control\Lsa\FIPSAlgorithmPolicy", true);
    if (uac == null)
    {
        uac = Registry.LocalMachine.CreateSubKey(@"System\CurrentControlSet\Control\Lsa\FIPSAlgorithmPolicy");
    }
    return uac.GetValue(Name);
}

Just pass "Enabled" key into it and it will return 1 or 0 based on the enabled or disabled.

Upvotes: 1

Related Questions