Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.joshjdevl:libsodium-jni:'
}
dependencies {
implementation("com.github.joshjdevl:libsodium-jni:")
}
<dependency>
<groupId>com.github.joshjdevl</groupId>
<artifactId>libsodium-jni</artifactId>
<version></version>
</dependency>
libraryDependencies += "com.github.joshjdevl" % "libsodium-jni" % ""
:dependencies [[com.github.joshjdevl/libsodium-jni ""]]
This project is entirely maintained in my spare time. Donations are appreciated: :clap:<br/><br/> Bitcoin address: 1EC6j1f2sDGy9L8ma8FFfQyxt9mb9a6Xxy <br/> Bitcoin Cash address: 1PSxB3DRCkeaZK7nSbJ1hoxbsWAXwM8Hyx <br/> Ethereum address: 2f30c73e8d643356ebbcfee7013ccd03c05097fb <br/> Peercoin address: PQUavHtRCLtevq75GhLCec41nvDtmM4wvf <br/> Raiblocks address: xrb_1dxetbqeo38gcxejt8n6utajorrntbfrr1qftpw7qwarw6d8kp74fwmcuqi9 <br/> Monero address: 48btz6nV4SjWyhDpkXrVVXAtgN6aStdnz8weMyB6qAMhhBVqiy1v3HC6XL1j7K27ZfFRhpw3Y4A4uE8o2PXMxFxY1Q5gGvW
A Java JNI binding (to allow for Java and Android integration) to Networking and Cryptography library by Daniel J. Bernstein.
Why JNI and not JNA? JNI is much faster than JNA and JNI is faster than JNR.
If you do use this project in your research project, please do cite this repo. Thanks!
Credits to: <br/>
- Libsodium: author Frank Denis and Contributors
- Kalium: author abstractj and Contributors
- Robosodium: author GerardSoleCa
- libstodium: author ArteMisc
org.libsodium.jni
<dependency>
<groupId>com.github.joshjdevl.libsodiumjni</groupId>
<artifactId>libsodium-jni-aar</artifactId>
<version>2.0.1</version>
<type>aar</type>
</dependency>
// build.gradle
dependencies {
...
compile 'com.github.joshjdevl.libsodiumjni:libsodium-jni-aar:2.0.1'
}
xmlns:tools="http://schemas.android.com/tools"
and tools:replace="android:allowBackup"
to your Manifest:<!-- AndroidManifest.xml -->
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.name.myapp">
<application
...
tools:replace="android:allowBackup">
<activity android:name=".MainActivity">
...
</activity>
</application>
</manifest>
<dependency>
<groupId>com.github.joshjdevl.libsodiumjni</groupId>
<artifactId>libsodium-jni</artifactId>
<version>2.0.1</version>
<type>jar</type>
</dependency>
Example invocations
tools:replace="android:allowBackup"
// MainActivity.kt
import org.libsodium.jni.SodiumConstants
import org.libsodium.jni.crypto.Random
import org.libsodium.jni.keys.KeyPair
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Test Libsodium
val seed = Random().randomBytes(SodiumConstants.SECRETKEY_BYTES)
val encryptionKeyPair = KeyPair(seed)
Log.i("PUBLIC KEY:", encryptionKeyPair.publicKey.toString())
}
}
Install brew
Run ./build-mac.sh
Run ./build-linux.sh
The docker container is available from libsodium-jni which is a Automated Build.
Please refer to the docker build for the commands used to build.
A Vagrantfile is available for those that would like to set up a virtual machine.
Clone the repo and import project from folder example/Sodium in Android studio (Android studio 2.1). Android studio will handle the rest. Compile and run. Tested to emulators down to Android Version 16.
To use the AAR project as is (No .SO file imports needed).
It is also possible to build the AAR library yourself using the provided scripts linux or mac. After building the library open module settings and add the libsodium-jni-release.aar and/or libsodium-jni-debug.aar as a dependency.
To use the library with your own custom code, skip the aar file and add
libsodium-jni is currently being used in production. Feedback, bug reports and patches are always welcome. Everything has been tested and working on ubuntu 12.04 32bit and 64 bit, macos, and Android.
gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 4524D716
SWIG is used to generate the Java JNI bindings. This means that the same interface definition can be used to generate bindings for all languages supported by SWIG. The interface can be found here