Is System.Security.Cryptography namespace supporte

2020-07-06 05:26发布

I am converting an existing multi-target Silverlight/.NET project to a Portable Class Library project in order to reduce the number of projects that are required to support multiple Microsoft platforms.

I have an error in one class that is using the System.Security.Cryptography namespace

The type or namespace name 'Cryptography' does not exist in the namespace 'System.Security' (are you missing an assembly reference?)

This namespace is available in Silverlight and I am wondering why the Portable Class Library does not support it?

One reason could be that this behaviour is by design: any cryptography related code should not be present in a client side API.

4条回答
够拽才男人
2楼-- · 2020-07-06 05:50

I would suspect it does not support it. Members on classes in that Namespace are marked with an image:

You can find which members are supported by the Portable Class Library project in the reference topics for the .NET Framework Class Library. In the members table for a class, the following Portable Class Library icon appears next to supported members. Portable Class Library

That image is lacking in every class I examined in the documentation.

This namespace is available in Silverlight and I am wondering why the Portable Class Library does not support it?

I can't say for sure; but it does appear to be lacking under XNA for the XBox 360 platform. Even then, I believe your conclusion is correct - it isn't an API that is very popular on a front end. Then underlying code is also extremely non-portable. A large portion of the Crypto namespace is accomplished by P/Invoking down to the operating system. I suspect they could make it portable as they did with Silverlight; but that may just not have been on their radar just yet.

查看更多
兄弟一词,经得起流年.
3楼-- · 2020-07-06 05:52

I suggest you use PclCrypto. It's the simplest to use and invokes platform crypto rather than trying to implement it itself, which means less security risk and faster performance.

查看更多
太酷不给撩
4楼-- · 2020-07-06 05:53

"You can find which members are supported by the Portable Class Library project in the reference topics for the .NET Framework Class Library. In the members table for a class, the following Portable Class Library icon appears next to supported members. "

I would recommend using the object browser, as I have found examples of classes that the MSDN indicates are supported in the PCL, but are missing from the framework. Such an example is Lazy

(as of 2011-9-11)

查看更多
霸刀☆藐视天下
5楼-- · 2020-07-06 05:56

No unfortunately, Portable Library does not support Crypto. However, we've added support for it in PclContrib.

查看更多
登录 后发表回答