简体   繁体   中英

HMAC SHA256 in .NET .1.1

I have to dare with a web application developed in .NET 1.1 Framework , with no possibilities to upgrade to major versions.

Having said that, I need to encrypt a text using HMAC SHA256 .

I see that System.Security.Cryptography namespace in .NET 1.1 provides me a way to has a message in SHA256. But I need to use HMAC (Hash-based Message Authentication Code) with SHA256, so I send not only the text to encrypt, but also a key .

I see that .NET Framework 2.0 and later has an specific class HMACSHA256 to manage this. But haven't found an implementation for .NET 1.1.

¿Any help?

Thanks in advance

You can add to your project the file from Microsoft :

namespace System.Security.Cryptography {
    [System.Runtime.InteropServices.ComVisible(true)]
    public class HMACSHA256 : HMAC {
        //
        // public constructors
        //

        public HMACSHA256 () : this (Utils.GenerateRandom(64)) {}

        public HMACSHA256 (byte[] key) {
            m_hashName = "SHA256";

#if FEATURE_CRYPTO
            m_hash1 = GetHashAlgorithmWithFipsFallback(() => new SHA256Managed(), () => HashAlgorithm.Create("System.Security.Cryptography.SHA256CryptoServiceProvider"));
            m_hash2 = GetHashAlgorithmWithFipsFallback(() => new SHA256Managed(), () => HashAlgorithm.Create("System.Security.Cryptography.SHA256CryptoServiceProvider"));
#else
            m_hash1 = new SHA256Managed();
            m_hash2 = new SHA256Managed();
#endif // FEATURE_CRYPTO

            HashSizeValue = 256;
            base.InitializeKey(key);
        }
    }
}

It seems that all calls are based on class that exists in .Net 1.1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM