All Projects → joshjdevl → Libsodium Jni

joshjdevl / Libsodium Jni

Licence: gpl-3.0
(Android) Networking and Cryptography Library (NaCL) JNI binding. JNI is utilized for fastest access to native code. Accessible either in Android or Java application. Uses SWIG to generate Java JNI bindings. SWIG definitions are extensible to other languages.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Libsodium Jni

Swift Sodium
Safe and easy to use crypto for iOS and macOS
Stars: ✭ 400 (+154.78%)
Mutual labels:  cryptography, libsodium
Sodium compat
Pure PHP polyfill for ext/sodium
Stars: ✭ 736 (+368.79%)
Mutual labels:  cryptography, libsodium
Libsodium Php
The PHP extension for libsodium.
Stars: ✭ 507 (+222.93%)
Mutual labels:  cryptography, libsodium
Pgsodium
Modern cryptography for PostgreSQL using libsodium.
Stars: ✭ 202 (+28.66%)
Mutual labels:  cryptography, libsodium
Nim Libsodium
Nim wrapper for the libsodium library
Stars: ✭ 32 (-79.62%)
Mutual labels:  cryptography, libsodium
Nsec
A modern and easy-to-use cryptographic library for .NET Core based on libsodium
Stars: ✭ 217 (+38.22%)
Mutual labels:  cryptography, libsodium
Libsodium.js
libsodium compiled to Webassembly and pure JavaScript, with convenient wrappers.
Stars: ✭ 665 (+323.57%)
Mutual labels:  cryptography, libsodium
Sodiumoxide
Sodium Oxide: Fast cryptographic library for Rust (bindings to libsodium)
Stars: ✭ 596 (+279.62%)
Mutual labels:  cryptography, libsodium
Rbnacl
Ruby FFI binding to the Networking and Cryptography (NaCl) library (a.k.a. libsodium)
Stars: ✭ 910 (+479.62%)
Mutual labels:  cryptography, libsodium
Halite
High-level cryptography interface powered by libsodium
Stars: ✭ 933 (+494.27%)
Mutual labels:  cryptography, libsodium
Kalium
Java binding to the Networking and Cryptography (NaCl) library with the awesomeness of libsodium
Stars: ✭ 203 (+29.3%)
Mutual labels:  cryptography, libsodium
Libsodium Go
A complete overhaul of the Golang wrapper for libsodium
Stars: ✭ 105 (-33.12%)
Mutual labels:  cryptography, libsodium
Enacl
Erlang bindings for NaCl / libsodium
Stars: ✭ 159 (+1.27%)
Mutual labels:  cryptography, libsodium
Sapient
Secure API Toolkit
Stars: ✭ 308 (+96.18%)
Mutual labels:  cryptography, libsodium
Pynacl
Python binding to the Networking and Cryptography (NaCl) library
Stars: ✭ 761 (+384.71%)
Mutual labels:  cryptography, libsodium
Lazysodium Android
An Android implementation of the Libsodium cryptography library. For the lazy dev.
Stars: ✭ 69 (-56.05%)
Mutual labels:  cryptography, libsodium
Streamcryptor
Stream encryption & decryption with libsodium and protobuf
Stars: ✭ 112 (-28.66%)
Mutual labels:  cryptography, libsodium
Cryptokernel
A SDK for implementing blockchain-based digital currencies
Stars: ✭ 146 (-7.01%)
Mutual labels:  cryptography
Shamir
A Java implementation of Shamir's Secret Sharing algorithm over GF(256).
Stars: ✭ 153 (-2.55%)
Mutual labels:  cryptography
Simon Speck
The SIMON and SPECK families of lightweight block ciphers. #nsacyber
Stars: ✭ 146 (-7.01%)
Mutual labels:  cryptography

This project is entirely maintained in my spare time. Donations are appreciated: 👏

Bitcoin address: 1EC6j1f2sDGy9L8ma8FFfQyxt9mb9a6Xxy
Bitcoin Cash address: 1PSxB3DRCkeaZK7nSbJ1hoxbsWAXwM8Hyx
Ethereum address: 2f30c73e8d643356ebbcfee7013ccd03c05097fb
Peercoin address: PQUavHtRCLtevq75GhLCec41nvDtmM4wvf
Raiblocks address: xrb_1dxetbqeo38gcxejt8n6utajorrntbfrr1qftpw7qwarw6d8kp74fwmcuqi9
Monero address: 48btz6nV4SjWyhDpkXrVVXAtgN6aStdnz8weMyB6qAMhhBVqiy1v3HC6XL1j7K27ZfFRhpw3Y4A4uE8o2PXMxFxY1Q5gGvW

Build Status Maven Central

libsodium-jni - (Android) Java JNI binding to the Networking and Cryptography (NaCl) library

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:

Installation

  • Java package is under org.libsodium.jni
  • Maven coordinates are in the Sonatype OSS repository

Android Archive (AAR)

<dependency>
    <groupId>com.github.joshjdevl.libsodiumjni</groupId>
    <artifactId>libsodium-jni-aar</artifactId>
    <version>2.0.1</version>
    <type>aar</type>
</dependency>

Android Gradle (AAR)

  1. Add library to dependencies:
// build.gradle
dependencies {
    ...
    compile 'com.github.joshjdevl.libsodiumjni:libsodium-jni-aar:2.0.1'
}
  1. To fix the warning allowBackup, add 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>

Java Archive (JAR)

<dependency>
    <groupId>com.github.joshjdevl.libsodiumjni</groupId>
    <artifactId>libsodium-jni</artifactId>
    <version>2.0.1</version>
    <type>jar</type>
</dependency>

Usage

Java

Example invocations

  • import org.libsodium.jni.NaCl; (this calls System.loadLibrary("sodiumjni");)
  • call NaCl.sodium(). {whatever_method_you_want}
  • Note that Android allowBackup is set to false. WARNING Your application can override the allow backup, just be sure that there is no sensitive data or secrets that might be backed up. Option can be used with tools:replace="android:allowBackup"

Kotlin

// 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())
    }
}

Manual Compilation and Installation

MacOS Manual Compilation and Installation

Install brew

Run ./dependencies-mac.sh

Run ./build-mac.sh

Linux Manual Compilation and Installation

Run ./dependencies-linux.sh

Run ./build-linux.sh

Docker Container

The docker container is available from libsodium-jni which is a Automated Build.

Manual compilation and installation

Please refer to the docker build for the commands used to build.

Notes

Docker container

Vagrant

A Vagrantfile is available for those that would like to set up a virtual machine.

Example application

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.

Manual AAR usage

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.

Custom code usage

To use the library with your own custom code, skip the aar file and add

  1. The native .SO libraries in your project (Create jnilibs folder and make the required changes to the gradle file)
  2. Add the source code from the src folder and add your own additional code.

Issues / Improvements / Help Seeked ✌️

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 Extensions

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].