ektrah / nsec

A modern and easy-to-use cryptographic library for .NET 8+ based on libsodium
https://nsec.rocks
MIT License
386 stars 55 forks source link

NSec works on .NET MAUI (Android) #81

Open kerosina opened 3 months ago

kerosina commented 3 months ago

Hello, I got NSec working on Android.

For it to work, I had to edit NSec, remove the reference to libsodium and edit src/Interop/Interop.Libraries.cs, changing "libsodium" to "libsodium.so", then use that edited NSec with MAUI.

After that, I had to compile libsodium from source for android, grab the .so it built (the files along with it, like libsodium.a etc. aren't needed) and then put it inside the project, inside a folder called "arm64-v8a" that's inside a folder called "lib". The libsodium.so also had to have BuildAction of AndroidNativeLibrary.

The reason I had to remove the reference to libsodium was because, with it, the compiler would add the libsodium.so for linux aarch64 and not our custom android one, which the libsodium nuget package didn't contain. The reason Interop.Libraries.cs had to be modified was because MAUI wouldn't find "libsodium" if it was passed to DllImport, but it would find libsodium.so.

kerosina commented 3 months ago

This isn't an issue, but since theres no discussions tab I decided to post it here.