Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is System.Security.Cryptography namespace supported by the Portable Class Library

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.

like image 260
Alex Pop Avatar asked Oct 17 '11 13:10

Alex Pop


3 Answers

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

like image 130
David Kean Avatar answered Oct 16 '22 19:10

David Kean


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.

like image 4
vcsjones Avatar answered Oct 16 '22 21:10

vcsjones


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.

like image 4
Andrew Arnott Avatar answered Oct 16 '22 21:10

Andrew Arnott