Reputation: 1015
I'm using this code inside WPF application:
public static string EncryptString(string stringToEncrypt)
{
SHA256 hash = SHA256.Create();
byte[] stringHash = System.Text.Encoding.ASCII.GetBytes(stringToEncrypt);
byte[] encryptedString = hash.ComputeHash(stringHash);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < encryptedString.Length; i++)
sb.Append(encryptedString[i].ToString("X2"));
return sb.ToString();
}
But it doesn't work on Windows Phone 7 (SHA256.Create is not recognized).
Upvotes: 2
Views: 1591
Reputation: 106926
You will have to use the Silverlight SHA256 version as documented on MSDN. The blue phone icons marks members that are available on Windows Phone 7.
To create an instance you will have to call the constructor directly of the managed implementation:
var hash = new SHA256Managed();
Upvotes: 5