PCL EncryptedServiceClient

Hello

Are there any plans to support EncryptedServiceClient in PCL Clients?
If there are none, could you recommend some sort of easy solution?

Basically what we need is encrypted message over http in Xamarin application.

Regards

No a PCL client isn’t possible, it depends on .NET’s crypto classes.

Thank you for your quick response.

I have found “PCLCrypto” project on Git: https://github.com/aarnott/pclcrypto

in which author says:

This library does not implement crypto. It merely provides PCL-compatible APIs to invoke crypto, and at runtime the crypto offered by the platform is invoked.

Is there any way that we can use this library with SS to encrypt messages?

Kind regards

No it uses a completely different API, dependency, namespace, etc.

The source code depends on .NET Framework Crypto classes and isn’t compatible with PCL or PCL Crypto, but you may be able to use some of the source code by skipping PCL and copying directly it into your project. Most of source code for EncryptedServiceClient is in these 2 classes:

Thank you, that worked excellent.
Only problem was that FromJson and ToJson static methods are defined as internal so we created our class MyJsonServiceClient to expose this methods like this:

public class MyJsonServiceClient : JsonServiceClient
{
	public static T FromJson<T>(string json)
	{
		using (__requestAccess())
		{
			return json.FromJson<T>();
		}
	}

	public static string ToJson<T>(T o)
	{
		using (__requestAccess())
		{
			return o.ToJson();
		}
	}
}

Our solution (in case anyone needs it):

  1. Copy CryptUtils.cs and EncryptedServiceClient.cs in Android project
  2. Make copy of ServiceClientExtensions class from EncryptedServiceClient.cs and put it in PCL project but without GetEncryptedClient methods
  3. Create instances of IJsonServiceClient and IEncryptedClient in android project and send reference in PCL project
  4. use IEncryptedClient in PCL as in documentation
1 Like

FYI, I’ve just added the EncryptedServiceClient to the Xamarin iOS/Android and Mac client builds so you wont need to manually include the EncryptedServiceClient.cs files in the next v4.0.62 release which is also now available on MyGet