Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SHA1 (and whole Cryptography namespace) missing in Visual Studio 2012

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.

like image 991
Guillermo Orellana Ruiz Avatar asked Jun 25 '12 10:06

Guillermo Orellana Ruiz


3 Answers

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.

like image 157
Anders Gustafsson Avatar answered Sep 22 '22 19:09

Anders Gustafsson


Answer is, like Anders Gustafsson pointed, that in Metro System.Security.Cryptography is not supported. BUT you have Windows.Security.Cryptography instead.

like image 36
Guillermo Orellana Ruiz Avatar answered Sep 22 '22 19:09

Guillermo Orellana Ruiz


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

like image 22
webber2k6 Avatar answered Sep 24 '22 19:09

webber2k6