8

I am very interested in mobile app development using Xamarin. To provide secure communication I would like to use NaCl or more specific: libsodium.
On the libsodium website it says that there are three options to use libsodium with C#: libsodium-net, NSec and NitraLibSodium
My question: Which is the best wrapper to build mobile apps? What are the disadvantages and the advantages?

Thank you.

LeWimbes
  • 517
  • 1
  • 10
  • 25

1 Answers1

3

Before you are able to decide which of these libraries you would like to use, you need to decide the version of .NET that you will be using for your Xamarin project.

These packages have different dependencies, but will all ultimately need to be imported as a NuGet Package, from there you can use like any other NuGet package in your C# project.

For what it's worth, the one that looks most mature and has active development is NSec, so if you're planning on building on the latest .NET standard that is the one I would go with.

As far as the pros and cons of each related to its implementation of libsodium, I'll have to leave that answer up to someone else as I am not familiar with NaCl.

Hope this helps.

Garrett Manley
  • 337
  • 3
  • 11
  • Unfortunately it's not that easy, if you have a look at the implementation of [libsodium-net](https://github.com/adamcaudill/libsodium-net/blob/master/libsodium-net/Interop/SodiumLibrary.cs) or NSec, you can see that they are only wrappers around an unmanaged C library. This means we need to install the native library together with the dotnet wrapper, and it has to be built for the target platform (e.g. `libsodium.so` for Android). Those pre compiled C libraries are available for the Windows platform (MingW release version), but not for others like Android so it cannot be used cross platform. – martinstoeckli May 25 '19 at 16:00
  • 2
    @martinstoeckli You need to build libsodium yourself. For the Android platform see here: https://stackoverflow.com/questions/26856443 (only libsodium, leave out the kalium-jni part because we want to bind to a Xamarin project, not a Java project). I used Ubuntu, installed Android Studio, and installed the NDK using the SDK Manager. After you have built the three versions, add the .so files to your Android project into folders Lib/armeabi, Lib/armeabi-v7a, and Lib/x86. Choose Build Action 'AndroidNativeLibrary' for each. – thomiel Sep 14 '19 at 12:55
  • @thomiel - Thank you for the explanation, such an answer is what I hoped for. So it seems there is no way around setting up a Linux based system. It would be really helpful, if a pre-built library was obtainable like the Windows version. Maybe I will give it a try again. – martinstoeckli Sep 15 '19 at 13:39