• Stars
    star
    331
  • Rank 126,949 (Top 3 %)
  • Language
    Java
  • License
    GNU Lesser Genera...
  • Created almost 9 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Argon2 Binding for the JVM

Argon2 Binding for the JVM Build & test

This is a JVM binding for Argon2.

"Being a binding" means that it uses JNA to call a native C library. The advantage of this approach is that this uses the original implementation of the Argon2 authors and possibly a performance advantage. The drawback is that the native library must either be available on your system or must be included in argon2-jvm.

If you are using an OS or an architecture which is not that common (e.g. argon2-jvm has no support for BSD), this library will not work for you, if your system has no native installation of the Argon2 library.

Spring Security Crypto has a Argon2PasswordEncoder which doesn't have any dependencies on native C libraries, as it uses Bouncy Castle which implements the Argon2 algorithm in pure Java. And don't let the name "Spring Security Crypto" scare you, it has no dependency on Spring or Spring Security. If you don't need (for whatever reason) the native Argon2 library, I would suggest that you look at the Argon2PasswordEncoder from Spring Security Crypto.

I have prepared a small showcase project which demonstrates the use of Argon2 with Spring Security Crypto.

Maven

Without pre-compiled Argon2 libraries (recommended, install argon2 via your package manager):

<dependency>
    <groupId>de.mkammerer</groupId>
    <artifactId>argon2-jvm-nolibs</artifactId>
    <version>2.11</version>
</dependency>

With pre-compiled Argon2 libraries:

<dependency>
    <groupId>de.mkammerer</groupId>
    <artifactId>argon2-jvm</artifactId>
    <version>2.11</version>
</dependency>

Gradle

Without pre-compiled Argon2 libraries (recommended, install argon2 via your package manager):

implementation 'de.mkammerer:argon2-jvm-nolibs:2.11'

With pre-compiled Argon2 libraries:

implementation 'de.mkammerer:argon2-jvm:2.11'

Usage

This binding needs a compiled Argon2 library. It is recommended to install argon2 via your package manager. If you can't do that, use argon2-jvm with the included argon2 binary libraries or compile argon2 yourself. The following operating systems and architectures are supported in argon2-jvm:

  • Linux x86
  • Linux x86-64
  • Linux ARM
  • Linux ARM-64
  • Windows x86
  • Windows x86-64
  • Darwin (OSX)
  • Darwin (OSX) M1

See tested distributions for details on which distributions this has been tested.

import de.mkammerer.argon2.Argon2;
import de.mkammerer.argon2.Argon2Factory;

// Create instance
Argon2 argon2 = Argon2Factory.create();

// Read password from user
char[] password = readPasswordFromUser();

try {
    // Hash password
    String hash = argon2.hash(10, 65536, 1, password);

    // Verify password
    if (argon2.verify(hash, password)) {
        // Hash matches password
    } else {
        // Hash doesn't match password
    }
} finally {
    // Wipe confidential data
    argon2.wipeArray(password);
}

Recommended parameters

The recommended parameters for the hash call above can be found in the whitepaper, section 9.

You can use the method Argon2Helper.findIterations to find the optimal number of iterations on your system:

Argon2 argon2 = Argon2Factory.create();
// 1000 = The hash call must take at most 1000 ms
// 65536 = Memory cost
// 1 = parallelism
int iterations = Argon2Helper.findIterations(argon2, 1000, 65536, 1);

System.out.println("Optimal number of iterations: " + iterations);

Compile Argon2 yourself

If you prefer to install/compile argon2 on your own you should argon2-jvm-nolibs instead of argon2-jvm and compile argon2 yourself. It's not that hard :)

If you need help to build argon2, have a look at this documentation.

Technical details

This library uses JNA to communicate with the Argon2 C library.

Building it yourself

Run ./gradlew clean build to build and test the software.

License

Licensed under LGPL v3.

Maintainer

Moritz Kammerer (@phXql)

Contributing

See contributing guidelines.

Contributors

See contributors page.

More Repositories

1

snowflake-id

Generates Twitter-like Snowflake ids in Java
Java
40
star
2

aleksa

Aleksa is a small framework for writing Alexa Skills in Kotlin
Kotlin
35
star
3

kotlin-one-epub

Small python script to create one epub file from the Kotlin reference.
Python
19
star
4

wiremock-junit5

A JUnit 5 extension for WireMock
Java
17
star
5

kotlin-crypto-example

Example showcasing crypto with Kotlin
Kotlin
15
star
6

grpc-chat-kotlin

A chat based on gRPC, written in Kotlin.
Kotlin
14
star
7

restwars

An online game (like the good old browsergames) which can be played via a REST interface
Java
12
star
8

maven-to-plantuml

This small tool is intended to plot a graph to show the dependencies between Maven modules. It ignores external dependencies and shows only inter-module relationships.
Kotlin
11
star
9

jna-info

Tool to provide JNA information
Java
4
star
10

jackson-polymorphic-deserialization

Small showcase for Jacksons polymorphic deserialization feature
Java
4
star
11

argon2-playground

Uses Spring Security Crypto and BouncyCastle to do Argon2 hashing on the JVM without the need for native libraries.
Java
4
star
12

vhd-compact

Compacts VHDs.
C#
3
star
13

sonarqube-to-prometheus

Exports SonarQube metrics to Prometheus
Java
3
star
14

java-maven-skeleton

Starting point for Java & Maven projects
Java
3
star
15

easy-krypto

This Kotlin library aims to provide a simple way to encrypt and decrypt stuff in a secure manner.
Kotlin
2
star
16

noke

Web-based note taking software
Kotlin
1
star
17

kotlin-blockchain

A blockchain PoC written in Kotlin
Shell
1
star
18

ecc-playground

Playground project for ECC with Curve25519 and AES-GCM on the JVM
Kotlin
1
star
19

jwt-decode

Small tool to decode JWT, written in GO
Go
1
star
20

hibernate-metamodel-and-lombok

Small demo project which combines the Hibernate Metamodel with Lombok
Java
1
star
21

testcontainers-playground

Java
1
star
22

jvm-rsa-showcase

A small project showcasing a hybrid encryption scheme using RSA and AES in Java.
Java
1
star
23

keyczar-tutorial

A Keyczar tutorial which demostrates signed sessions.
Java
1
star
24

kotlin-default-map

A map which returns a default value for missing keys
Kotlin
1
star
25

restwars-kotlin

A browser-game style game, playable via a REST interface
Kotlin
1
star
26

raft

Raft implementation in Java, for fun.
Java
1
star
27

gamedev-server

A game server.
Java
1
star
28

mr-canary

A TCP reverse proxy with canaries built in.
Java
1
star
29

global-registry-vs-instance

Java
1
star
30

tink-test

Just some playing around with Google's Tink
Java
1
star
31

spring-response-headers

Sample application to show how to add headers to all Spring Boot responses.
Java
1
star
32

plantuml-templates

Templates for different PlantUML diagrams
1
star
33

chacha20-poly1305-java

Showcases the usage of the ChaCha20-Poly1305 cipher which has been integrated into Java 11
Java
1
star