A Scala Wrapper for libsodium
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
project
src
.gitignore
.travis.yml
LICENSE
README.md
build.sbt

README.md

Francium v0.1.0-SNAPSHOT Build Status

NOTE: STILL IN ACTIVE DEVELOPMENT

This project follows semantic versioning (roughly) and thus as the project is still at version 0 .x.x the API is very unstable and subject to change without warning, so here be dragons.

Introduction

A simple Scala JNA binding for libsodium with a nice API.

Francium does not expose the raw C libsodium API, instead it provides the functionality in a nicer more Scala friendly way.

Requirements

Quick Start Guide

Installation

Francium requires libsodium to be in your PATH at runtime.

SBT Instructions Coming Soon

Building

Checkout the Github repo and run sbt build or sbt test to run the test suite.

Example Usage

Hashing

Do not use these hashing functions for hashing passwords, see Password Hashing for password hashing methods. All these hashing functions return a hex string.

SHA256

Note that this and SHA512 are provided only for interoperability with other applications and should not be used in other cases see the libsodium documentation for more information.

import com.github.errorhandler.francium.hashing._

val hash = "Some kind of data to hash".hashSHA256.getHexString // hash = 986f57825bb5f2a6891c9966f49b796332607edae503b6650c958bce74193e31
SHA512

Note that this and SHA256 are provided only for interoperability with other applications and should not be used in other cases see the libsodium documentation for more information.

import com.github.errorhandler.francium.hashing._

val hash = "Some kind of data to hash".hashSHA512.getHexString // hash = ada3116e79c0a46064a9e8bf4816b9356ad326e5c61795aa0a4d74593f4f86272eab4ee06313760408eb82285bfdc8ab485248b9533e4e10ec3afb6953167c73
BLAKE2b

BLAKE2b hashing is the default hashing algorithm in libsodium, so String.hash defaults to this.

import com.github.errorhandler.francium.hashing._

val hash1 = "Some kind of data to hash".hash.getHexString // hash1 = 4caa6bd586d1b0feb7e9111f05e1fbfb64aaf86ac947d16a8e8add60dd34f398fffbca6aa6149d70b14916bfd24fb6c855e33c16b3ee76eb7449be2f4b092638
val hash2 = "Some kind of data to hash".hashBLAKE2b.getHexString // hash2 = 4caa6bd586d1b0feb7e9111f05e1fbfb64aaf86ac947d16a8e8add60dd34f398fffbca6aa6149d70b14916bfd24fb6c855e33c16b3ee76eb7449be2f4b092638
hash1 == hash2 // true

Password Hashing

The Password object provides a mechanism for hashing passwords using the Argon2 scheme, winner of the Password Hashing Competition. See the libsodium documentation for more information. Password.hash uses the default libsodium password hash function and this includes a secure random salt by default so no salt needs to be provided.

import com.github.errorhandler.francium.Password

val password = "$ecure_password_1980"
val passwordHash = Password.hash(password) // $argon2id$v=19$m=65536,t=2,p=1$dMkr9QELIM+HKRymw+ERjA$FFhUwVPawwALNSqJ2pANYJ1N+BpwQAmxRKzR2tEh1o
Password.verify(passwordHash, "foobar") // false
Password.verify(passwordHash, password) // true

License

Apache 2. See the LICENSE file for details.