I copy-pasted from MSDN this code:
using System.Security.Cryptography;
byte[] buffer = enc.GetBytes(text);
SHA1CryptoServiceProvider cryptoTransformSHA1 =
new SHA1CryptoServiceProvider();
string hash = BitConverter.ToString(
cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", "");
return hash;
but VS says there is no such Cryptography
namespace, thus there is no SHA1CryptoServiceProvider
class.
What am I doing wrong?
I am using Visual Studio Professional 2012 RC with Dreamspark license on Windows 8 Release Preview.
I take it that you are trying to create a Metro application? Metro-style applications do not support the System.Security.Cryptography
namespace. The complete list of supported .NET API namespaces for Metro applications can be found here.
UPDATE JUNE 29
As Guillermo has pointed out though, there is the Windows.Security.Cryptograhy.Core namespace, that contains a HashAlgorithmProvider class where e.g. the SHA1 algorithm can be applied.
Answer is, like Anders Gustafsson pointed, that in Metro System.Security.Cryptography
is not supported. BUT you have Windows.Security.Cryptography
instead.
Try to add System.Security
to the references of your project.
Your error seems to be caused by this missing reference.
http://msdn.microsoft.com/en-us/library/wkze6zky(v=vs.110).aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With