0

I am trying to retrieve contacts from hotmail in asp.net mvc. The response of hotmail api contains email as email hash and i know we cannot decrypt that email address hash. and There i saw one more field name field that contains actual contact email address.how could i calculate hash for that email address using sHA56 hasing.

Karthik Bammidi
  • 1,851
  • 9
  • 31
  • 65

1 Answers1

0

What about that? It assumes the strings to hash are encoded in UTF-8, the article you linked doesnt mention the Encoding that should be used.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace TestSHAHash
{
    class Program
    {
        static void Main(string[] args)
        {
            string email = "Someone@Example.org";
            string clientId = "0000000603DB0F";

            string toHash = (email.Trim() + clientId.Trim()).ToLowerInvariant();
            byte[] data = Encoding.UTF8.GetBytes(toHash);
            byte[] result;
            SHA256 shaM = new SHA256Managed();
            result = shaM.ComputeHash(data);
            string lowerHexaDecimal = BitConverter.ToString(result).Replace("-","").ToLowerInvariant();
            Console.WriteLine(lowerHexaDecimal);
            Console.ReadLine();
        }
    }
}
Jf Beaulac
  • 5,206
  • 1
  • 25
  • 46
  • thanks for your response. But the result of calculating hash for email address by following the article [link](http://msdn.microsoft.com/en-us/library/live/hh826530.aspx#generating) was not matched with Email hash in hotmail api response. – Karthik Bammidi Jun 06 '12 at 19:52
  • edited based on the information available in the article you linked – Jf Beaulac Jun 06 '12 at 20:03
  • You are following the 6 steps in that article and using the above SHA256Managed code to do step #5 correct? Obviously if you don't follow all of the preceding steps or the subsequent step then it won't have the same result. – stephen.vakil Jun 06 '12 at 20:04