2012-01-31 63 views
4

我正在构建FIPS验证的应用程序,并在我的计算机上启用了FIPS模式。我需要一个基于SHA512的HMAC函数。据我所知,HMAC SHA1函数经FIPS验证,但我有一个经过FIPS验证的散列函数SHA512CryptoServiceProvider,并且我知道FIPS实际上允许SHA512。在FIPS中验证HMAC SHA512的C#中是否有类似的HMAC功能?基于SHA512的FIPS验证应用程序与HMAC功能?

回答

7

有一个HMACSHA512 Class,但它在内部使用SHA512Managed Class,这是not FIPS certified

你可以基于该SHA512CryptoServiceProvider Class尝试create your own HMACSHA512 Class

public class MyHMACSHA512 : HMAC 
{ 
    public MyHMACSHA512(byte[] key) 
    { 
     HashName = "System.Security.Cryptography.SHA512CryptoServiceProvider"; 
     HashSizeValue = 512; 
     BlockSizeValue = 128; 
     Key = key; 
    } 
} 
+0

Yah多数民众赞成真正的唯一的问题是,与FIPS兼容性打开它不起作用。我需要一个兼容FIPS的HMAC SHA512。例如,SHA512Cng在FIPS兼容模式下打破,SHA512CryptoServiceProvider不打开。 HMACSHA512在FIPS兼容模式下断开HMACSHA1没有。我想找到一个基于SHA512的HMAC,它不会中断FIPS兼容性。 – hobeau 2012-01-31 14:00:22

+0

我明白了。默认情况下,HMACSHA512类内部使用SHA512Managed类,该类未经FIPS验证。您可以尝试基于SHA512CryptoServiceProvider类创建您自己的HMACSHA512类。 – dtb 2012-01-31 14:22:39

+0

感谢您的回复。我尝试了这种方法,但我有例外。它看起来像SHA512CryptoServiceProvider不是一个有效的哈希名称http://msdn.microsoft.com/en-us/library/kczffhwa.aspx – hobeau 2012-01-31 15:20:51

2

以下为我工作 - 我可以同时创建AES和SHA256 FIPS快乐HMAC:

/// <summary>Computes a Hash-based Message Authentication Code (HMAC) using the AES hash function.</summary> 
    public class AesHmac : HMAC 
    { 
     /// <summary>Initializes a new instance of the AesHmac class with the specified key data.</summary> 
     /// <param name="key">The secret key for AesHmac encryption.</param> 
     public AesHmac(byte[] key) 
     { 
      HashName = "System.Security.Cryptography.AesCryptoServiceProvider"; 
      HashSizeValue = 128; 
      BlockSizeValue = 128; 
      Initialize(); 
      Key = (byte[])key.Clone(); 
     } 
    } 

    /// <summary>Computes a Hash-based Message Authentication Code (HMAC) using the SHA256 hash function.</summary> 
    public class ShaHmac : HMAC 
    { 
     /// <summary>Initializes a new instance of the ShaHmac class with the specified key data.</summary> 
     /// <param name="key">The secret key for ShaHmac encryption.</param> 
     public ShaHmac(byte[] key) 
     { 
      HashName = "System.Security.Cryptography.SHA256CryptoServiceProvider"; 
      HashSizeValue = 256; 
      BlockSizeValue = 128; 
      Initialize(); 
      Key = (byte[])key.Clone(); 
     } 
    } 

谢谢, Ritchie

相关问题