Tuesday, 1 October 2013

Generating PHP SHA1 Hash in Windows Phone and Windows 8 App

If you want to generate the PHP SHA1 (sometimes called hex digest format) in windows phone or windows 8 app us the following method.

private string HashString(string str)
 string dataHash = string.Empty;
 string hashType = "SHA1";

  HashAlgorithmProvider Algorithm = HashAlgorithmProvider.OpenAlgorithm(hashType);
  IBuffer vector = CryptographicBuffer.ConvertStringToBinary(str, BinaryStringEncoding.Utf8);
  IBuffer digest = Algorithm.HashData(vector);

  if (digest.Length != Algorithm.HashLength)
   throw new System.InvalidOperationException("Failed");
  dataHash = CryptographicBuffer.EncodeToHexString(digest); 
  return dataHash;
 catch (Exception){}

 return null;

1 comment:

  1. I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts.
    Cyber Security Projects for Final Year

    JavaScript Training in Chennai

    Project Centers in Chennai

    JavaScript Training in Chennai