The following forum(s) are migrating to a new home on Microsoft Q&A (Preview): Developing Universal Windows apps!

Ask new questions on Microsoft Q&A (Preview).
Interact with existing posts until December 13, 2019, after which content will be closed to all new and existing posts.

Learn More

 none
HMACMD5 encryption algorithm in Universal Windows apps or UWP RRS feed

  • Question

  • Hi

    I need  HMACMD5 encryption algorithm in UWP.Came to know this algorithm is not available is it  If yes please any third party nuget or library to implement same Or Tell name of the namespace need to reference if this encryption available.

    thank you



    • Edited by Arun_G Wednesday, March 15, 2017 6:13 AM
    Wednesday, March 15, 2017 6:07 AM

Answers

  • Hello Arun_G,

    HMAC-MD5 is supported in UWP. So you can use it through standard APIs. 

    e.g.

    //using Windows.Security.Cryptography;
    //using Windows.Security.Cryptography.Core;
    
        var provider = MacAlgorithmProvider.OpenAlgorithm(MacAlgorithmNames.HmacMd5);
        var key = CryptographicBuffer.DecodeFromHexString("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b");
        var data = CryptographicBuffer.ConvertStringToBinary("Hi There", BinaryStringEncoding.Utf8);
    
        var hmac = provider.CreateHash(key);
        hmac.Append(data);
        var digest = hmac.GetValueAndReset();
    
        Debug.WriteLine(CryptographicBuffer.EncodeToHexString(digest));
        // Output:
        // 9294727a3638bb1c13f48ef8158bfc9d
    

    • Marked as answer by Arun_G Thursday, March 16, 2017 9:58 AM
    • Edited by FEC-4RP Friday, March 17, 2017 2:03 AM
    Thursday, March 16, 2017 5:24 AM

All replies

  • Hello Arun_G,

    HMAC-MD5 is supported in UWP. So you can use it through standard APIs. 

    e.g.

    //using Windows.Security.Cryptography;
    //using Windows.Security.Cryptography.Core;
    
        var provider = MacAlgorithmProvider.OpenAlgorithm(MacAlgorithmNames.HmacMd5);
        var key = CryptographicBuffer.DecodeFromHexString("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b");
        var data = CryptographicBuffer.ConvertStringToBinary("Hi There", BinaryStringEncoding.Utf8);
    
        var hmac = provider.CreateHash(key);
        hmac.Append(data);
        var digest = hmac.GetValueAndReset();
    
        Debug.WriteLine(CryptographicBuffer.EncodeToHexString(digest));
        // Output:
        // 9294727a3638bb1c13f48ef8158bfc9d
    

    • Marked as answer by Arun_G Thursday, March 16, 2017 9:58 AM
    • Edited by FEC-4RP Friday, March 17, 2017 2:03 AM
    Thursday, March 16, 2017 5:24 AM
  • Ok thank you .
    Thursday, March 16, 2017 9:58 AM