Visual Studio 2012中缺少SHA1(和整个Cryptography命名空间)

Gui*_*uiz 7 c# visual-studio-2012

我从MSDN复制粘贴此代码:

using System.Security.Cryptography;

byte[] buffer = enc.GetBytes(text);
SHA1CryptoServiceProvider cryptoTransformSHA1 =
            new SHA1CryptoServiceProvider();
string hash = BitConverter.ToString(
            cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", "");

return hash;
Run Code Online (Sandbox Code Playgroud)

但VS说没有这样的Cryptography命名空间,因此没有SHA1CryptoServiceProvider类.

我究竟做错了什么?

我在Windows 8 Release Preview上使用带有Dreamspark许可证的Visual Studio Professional 2012 RC.

And*_*son 5

我认为您正在尝试创建Metro应用程序?Metro风格的应用程序不支持System.Security.Cryptography命名空间.可在此处找到Metro应用程序支持的.NET API命名空间的完整列表.

更新6月29日

正如Guillermo指出的那样,有一个Windows.Security.Cryptograhy.Core命名空间,它包含一个HashAlgorithmProvider类,例如可以应用SHA1算法.

  • 怎么可能?这是否意味着如果我想要Metro应用程序,我不能再使用SHA-1了? (2认同)

Gui*_*uiz 5

答案就像Anders Gustafsson指出的那样,System.Security.Cryptography不支持Metro .但你有Windows.Security.Cryptography.