具有基于 SHA512 的 HMAC 功能的 FIPS 验证应用程序?

发布于 2024-12-29 22:44:54 字数 219 浏览 3 评论 0 原文

我正在构建一个经过 FIPS 验证的应用程序,并在我的计算机上打开了 FIPS 模式。我需要一个基于 SHA512 的 HMAC 函数。我知道 HMAC SHA1 函数经过 FIPS 验证,但我有一个哈希函数 SHA512CryptoServiceProvider,它经过 FIPS 验证,并且我知道 FIPS 实际上允许 SHA512。 C# 中是否有类似的 HMAC 函数可以对 FIPS 验证 HMAC SHA512?

I'm building a FIPS validated application and have the FIPS mode turned on on my computer. I need an HMAC function hopefully based on SHA512. I understand that the HMAC SHA1 function is FIPS validated but I have a hash function SHA512CryptoServiceProvider which is FIPS validated and I know that FIPS does in fact allow for SHA512. Is there a similar HMAC function in C# that does FIPS validated HMAC SHA512?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

十秒萌定你 2025-01-05 22:44:54

有一个 HMACSHA512 类,但它使用 SHA512托管类内部,这是未经过 FIPS 认证< /a>.

您可以尝试 基于 href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.sha512cryptoserviceprovider.aspx">SHA512CryptoServiceProvider 类

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

There is a HMACSHA512 Class, but it uses the SHA512Managed Class internally, which is not FIPS certified.

You could try to create your own HMACSHA512 Class based on the SHA512CryptoServiceProvider Class:

public class MyHMACSHA512 : HMAC
{
    public MyHMACSHA512(byte[] key)
    {
        HashName = "System.Security.Cryptography.SHA512CryptoServiceProvider";
        HashSizeValue = 512;
        BlockSizeValue = 128;
        Key = key;
    }
}
我是有多爱你 2025-01-05 22:44:54

以下内容对我有用 - 我能够创建 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();
        }
    }

谢谢,
里奇

The following worked for me - I was able to create both an AES and SHA256 FIPS happy 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();
        }
    }

Thanks,
Ritchie

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文