Java binding to the Networking and Cryptography (NaCl) library with the awesomeness of libsodium

Overview

License Maven Central Build Status Build status Say Thanks

kalium - Java binding to the Networking and Cryptography (NaCl) library

A Java binding to Networking and Cryptography library by Daniel J. Bernstein. All the hard work of making a portable NaCl API version was done by Frank Denis on libsodium and kalium was totally inspired by Tony Arcieri's work with RbNaCl.

Requirements

Installation

libsodium

kalium is implemented using jnr-ffi to bind the shared libraries from libsodium. For a more detailed explanation, please refer to RbNaCl's documentation.

OSX

OS X users can get libsodium via homebrew with:

brew install libsodium

Windows

Windows users will need to provide the pre-build binaries from libsodium.

  • Download libsodium from https://download.libsodium.org/libsodium/releases/
  • Choose the version of libsodium you wish to use
    • The archives follow the following pattern: libsodium-{version}-msvc.zip
  • From the archive find the artifacts compiled for your architecture and then the MSVC tool set of your choice
    • For example: v141 // these were compiled against the MSVC v141 (i.e. Visual Studio 2017)
  • Extract from the archive the dll library files into one of the following locations:
    • into the lib at the root of the working directory directory of your project.
    • into a location that is included in your PATH environment variable.

For example, on Windows 10 machine with a x64 architecture:

{archive root}
└───x64
    ...
    └───Release
        ...
        └───v141
            ...
            └───dynamic <- copy the library files from this locaiton.

kalium installation

Add as a Maven dependency to your project.

FAQ

Is Android supported?

No.

Would be nice to have some documentation. Do you have some?

Look at the libsodium docs, they are self explanatory. Or, contribute with docs.

I'm experiencing some issues on Windows. Do you have any idea?

I'm sorry but I'm completely clueless about Windows environment, but if you have any suggestions or PR changes. They will be more than welcome.

Notes

Kalium is the effort of a really small group of people, feedback, bug reports and patches are always welcome.

Comments
  • BLAKE2b default digest length: 32 or 64?

    BLAKE2b default digest length: 32 or 64?

    src/libsodium/include/sodium/crypto_generichash_blake2b.h, line 46:

    #define crypto_generichash_blake2b_BYTES         32U
    

    org.abstractj.kalium/NaCl line #80:

     public static final int BLAKE2B_OUTBYTES = 64;
    

    Is that intentional?

    bug 
    opened by lvh 12
  • kalium doesn't call sodium_init()

    kalium doesn't call sodium_init()

    sodium_init is responsible for access to /dev/urandom. However, Random.java appears to work fine and have tests... I'm not sure what sodium does if you forget to call sodium_init; it may lazily open urandom, which is usually fine except when it's not (chroots come to mind).

    opened by lvh 9
  • Kalium 1.0.0?

    Kalium 1.0.0?

    I started off with the goal of adding all of the currently documented Libsodium interfaces to Kalium. I may have gotten a bit carried away cleaning up code though. Anyway this is my progress so far, no need to merge yet.

    Goals

    • Add all of the documented libsodium interfaces
    • Provide OO style interfaces
    • Review other OO style bindings to libsodium to see if we can make Kalium's bindings better
    • Take a crack at #41
    • Keep backwards compatibility to Kalium 0.4.0
    opened by bendoerr 8
  • java.lang.NoClassDefFoundError: jnr/ffi/Platform$OS

    java.lang.NoClassDefFoundError: jnr/ffi/Platform$OS

    Just added a maven dependency to Kalium to my project

    <dependency>
    			<groupId>org.abstractj.kalium</groupId>
    			<artifactId>kalium</artifactId>
    			<version>0.6.0</version>
    		</dependency>
    

    Attempting to use the framework, I'm running into the following exception:

    java.lang.NoClassDefFoundError: jnr/ffi/Platform$OS
    	at org.abstractj.kalium.NaCl$1.<clinit>(NaCl.java:37) ~[kalium-0.6.0.jar:na]
    	at org.abstractj.kalium.NaCl.libraryName(NaCl.java:37) ~[kalium-0.6.0.jar:na]
    	at org.abstractj.kalium.NaCl.<clinit>(NaCl.java:34) ~[kalium-0.6.0.jar:na]
    	at org.abstractj.kalium.crypto.Password.verify(Password.java:35) ~[kalium-0.6.0.jar:na]
    

    Do I have to bundle any DLL of sodium with my application? I was hoping you would package that for me with the Kalium jar file.

    Cheers, Florian

    help-wanted windows 
    opened by florianschneider 6
  • New release to support library name differences in NaCl?

    New release to support library name differences in NaCl?

    I recently ran into the issue described in #65. I see that it is marked as revolved and merged. Do you have an ETA for a release of kalium with this change? Or should I post a PR with doc changes suggesting how to work around this?

    help-wanted windows 
    opened by agarbutt 6
  • Util.isValid should throw specific exception type

    Util.isValid should throw specific exception type

    If the encryption / decryption fails on SecretBox, then Util.isValid is called -- this throws RuntimeException.

    https://github.com/abstractj/kalium/blob/master/src/main/java/org/abstractj/kalium/crypto/Util.java#L46

    Because RuntimeException is so general, if I want to catch this specific exception I have to check the message:

    https://github.com/wsargent/play-kalium/blob/master/app/controllers/HomeController.scala#L25

    This is not good -- there should be a specific EncryptionFailedException that extends from RuntimeException that can be checked individually.

    opened by wsargent 6
  • Adds constant time (for length) operations.

    Adds constant time (for length) operations.

    This adds equals, compare, and isZero operations to Util.java that are comparable to sodium/util.h versions.

    Running these functions in Java is much faster than going though to the overhead to the native libsodium implementations.

    • memcmp -> https://github.com/jedisct1/libsodium/blob/1.0.8/src/libsodium/sodium/utils.c#L98-L117
    • compare -> https://github.com/jedisct1/libsodium/blob/1.0.8/src/libsodium/sodium/utils.c#L132-L155
    • is_zero -> https://github.com/jedisct1/libsodium/blob/1.0.8/src/libsodium/sodium/utils.c#L158-L167
    opened by bendoerr 6
  • java.lang.IncompatibleClassChangeError: Found interface org.objectweb.asm.ClassVisitor, but class was expected

    java.lang.IncompatibleClassChangeError: Found interface org.objectweb.asm.ClassVisitor, but class was expected

    I cannot use kalium at all:

    java.lang.IncompatibleClassChangeError: Found interface org.objectweb.asm.ClassVisitor, but class was expected
        at jnr.ffi.provider.jffi.AsmLibraryLoader.generateInterfaceImpl(AsmLibraryLoader.java:74)
        at jnr.ffi.provider.jffi.AsmLibraryLoader.loadLibrary(AsmLibraryLoader.java:59)
        at jnr.ffi.provider.jffi.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:43)
        at jnr.ffi.LibraryLoader.load(LibraryLoader.java:265)
        at jnr.ffi.LibraryLoader.load(LibraryLoader.java:244)
        at org.abstractj.kalium.NaCl$SingletonHolder.<clinit>(NaCl.java:41)
        at org.abstractj.kalium.NaCl.sodium(NaCl.java:28)
    [...]
    
    opened by iphydf 6
  • Update KeyPair.java

    Update KeyPair.java

    Fix: If a new KeyPair was created based on an existing PrivateKey the publicKey-field stayed null forever. Each time .getPublicKey() was called the PublicKey was recalculated.

    Moved this code in the constructor where it belongs to.

    opened by jahoefne 6
  • Have to rename libsodium.dll -> sodium.dll so that jnr-ffi could find library

    Have to rename libsodium.dll -> sodium.dll so that jnr-ffi could find library

    Hi! I downloaded latest release of libsodium (https://download.libsodium.org/libsodium/releases/libsodium-1.0.11-msvc.zip), extracted appropriate libsodium.dll, set up java.library.path property... but jnr-ffi failed to load sodium library (throws LinkageError). If I rename libsodium.dll to sodium.dll it works fine. Is it correct behaviour on Windows platform?

    OS: Windows 7 SP1 x86 Kalium 0.5.0

    opened by nartamonov 5
  • Segfault if SealedBox pubkey is null

    Segfault if SealedBox pubkey is null

    See https://github.com/ysangkok/NaclTest/blob/master/src/main/java/com/mycompany/nacltest/NaclTest.java

    If I change the public key parameter to null (public key shouldn't be needed for decryption, right?), the JVM crashes.

    Even if a public key is needed, it should not segfault, it could throw an exception.

    Why are annotations such as @Nullable not used?

    Thanks for you efforts however, the library is useful.

    opened by ysangkok 5
  • BLAKE2b-256

    BLAKE2b-256

    hashPrevouts: BLAKE2b-256('ZcashPrevoutHash',b'') = d53a633bbecf82fe9e9484d8a0e727c73bb9e68c96e72dec30144f6a84afa136 How to write this project, thank you @abstractj

    opened by xianaofei 0
  • add support for LD_LIBRARY_PATH env var

    add support for LD_LIBRARY_PATH env var

    It would be very convenient to have more control on the paths (and order) queried for loading native libraries (apart from the std three currently taken into account); prepending the paths from LD_LIBRARY_PATH evn var would be a very welcome addition and common linux behavior.

    The underlying jnr-ffi lib does allow to append some extra paths, but unfortunately those did not help us out (ref https://github.com/jnr/jnr-ffi/issues/129). They were only appended to the std search paths.

    opened by roomsg 0
  • Specify Encoding for Version String (#87)

    Specify Encoding for Version String (#87)

    Added an annotation to the sodium_version_string() method so it is always read as an ASCII string. Avoids some issues on Windows with reading multi-byte strings by default.

    Added a test to make sure version string matches the expected pattern.

    For issue #87.

    opened by m4dc4p 3
  • Exception During Initialization (Windows)

    Exception During Initialization (Windows)

    Kalium with libsodium 1.0.15 & 1.0.16 is broken, due to incorrect string handling in jnr-ffi.

    • libsodium stores the version string in 1.0.15 as 1.0.15\0\0xsalsa20.... (https://github.com/jedisct1/libsodium/issues/665)
    • jnr-ffi does not correctly read NULL-terminated static strings from binaries - its look for a double null (\0\0\0\0). (https://github.com/jnr/jnr-ffi/issues/108)

    As a result, sodium_lib_version returns "1.0.15\0\0xsalsa20", and checkVersion fails because it tries to convert 15\0\0xsalsa20 to an integer.

    Short of fixing jnr-ffi, Kalium could update its regex when parsing the input string to avoid this bug.

    opened by m4dc4p 3
Owner
Bruno Oliveira da Silva
Bruno Oliveira da Silva
Java Project based on Java and Encryption using Cryptography algorithms

Symmetric-Encryption-Cryptography-in-Java Java Project based on Java and Encryption using Cryptography algorithms Project Aim Develop Java program to

Muhammad Asad 6 Feb 3, 2022
State-of-the-art cryptography to protect your world seed against seed cracking tools

SecureSeed State-of-the-art cryptography to protect your world seed against seed cracking tools. This mod is written for the Fabric Mod Loader. If you

Joseph Burton 55 Dec 28, 2022
This App is a command line application, based on Cryptography.

This App is a command line application, based on Cryptography. where a user input a text and its encrypted and can be decrypted as well.

Mohamed Ibrahim 1 Jan 28, 2022
A small and easy-to-use one-time password generator library for Java according to RFC 4226 (HOTP) and RFC 6238 (TOTP).

OTP-Java A small and easy-to-use one-time password generator for Java according to RFC 4226 (HOTP) and RFC 6238 (TOTP). Table of Contents Features Ins

Bastiaan Jansen 106 Dec 30, 2022
A small and easy-to-use one-time password generator library for Java according to RFC 4226 (HOTP) and RFC 6238 (TOTP).

OTP-Java A small and easy-to-use one-time password generator for Java according to RFC 4226 (HOTP) and RFC 6238 (TOTP). Table of Contents Features Ins

Bastiaan Jansen 106 Dec 30, 2022
A library for bypassing all of Java's security mechanisms, visibility checks, and encapsulation measures via the JNI API

Narcissus: thwart strong encapsulation in JDK 16+ Narcissus is a JNI native code library that provides a small subset of the Java reflection API, whil

ToolFactory 29 Nov 3, 2022
Password4j is a user-friendly cryptographic library that supports Argon2, Bcrypt, Scrypt, PBKDF2 and various cryptographic hash functions.

Password4j is a Java user-friendly cryptographic library for hashing and checking passwords with different Key derivation functions (KDFs) and Cryptog

Password4J 246 Jan 5, 2023
Tink is a multi-language, cross-platform, open source library that provides cryptographic APIs that are secure, easy to use correctly, and hard(er) to misuse.

Tink A multi-language, cross-platform library that provides cryptographic APIs that are secure, easy to use correctly, and hard(er) to misuse. Ubuntu

Google 12.9k Jan 3, 2023
The react-native Baidu voice library provides voice recognition, voice wake-up and voice synthesis interfaces. react-native百度语音库,提供语音识别,语音唤醒以及语音合成接口。

react-native-baidu-asr react-native-baidu-asr It is a Baidu speech library under React Native, which can perform speech recognition, speech wake-up an

dengweibin 11 Oct 12, 2022
An authorization library that supports access control models like ACL, RBAC, ABAC in Java

jCasbin News: still worry about how to write the correct jCasbin policy? Casbin online editor is coming to help! Try it at: http://casbin.org/editor/

Casbin 2k Dec 30, 2022
A Twitter-API library JAVA

Tweety A Twitter-API library for JAVA. Code for Authorization (Oauth 1) can be found here :Authorization This api conta

Rohit Kumar 2 Apr 26, 2022
Java Secure Cookie Library

Java library for security cookies, client-side pieces of data protected from reading and modifications by client with strong cryptography

Sergey Vladimirov 1 Oct 9, 2022
This is an android library to represent password strength.

PasswordStrengthView This is an android library to represent password strength. Preview How to use? Add maven to your project gradle file allprojects

null 33 Jan 3, 2022
Library to easily configure API Key authentication in (parts of) your Spring Boot Application

42 API Key Authentication A library to easily configure API Key authentication in (parts of) your Spring Boot Application. Features Easily configure A

null 2 Dec 8, 2021
ByteSkriptQuery - A library for deploying ByteSkript as a backend web technology.

ByteSkriptQuery A language library for ByteSkript that allows it to be deployed as a backend web language. Not only does this allow the creation of ad

null 1 Jan 4, 2022
Java JWT: JSON Web Token for Java and Android

Java JWT: JSON Web Token for Java and Android JJWT aims to be the easiest to use and understand library for creating and verifying JSON Web Tokens (JW

null 8.8k Dec 30, 2022
A mitigation for CVE-2021-44228 (log4shell) that works by patching the vulnerability at runtime. (Works with any vulnerable java software, tested with java 6 and newer)

Log4jPatcher A Java Agent based mitigation for Log4j2 JNDI exploits. This agent employs 2 patches: Disabling all Lookup conversions (on supported Log4

null 45 Dec 16, 2022
Open Source Identity and Access Management For Modern Applications and Services

Keycloak Keycloak is an Open Source Identity and Access Management solution for modern Applications and Services. This repository contains the source

Keycloak 14.6k Jan 5, 2023