joy-framework / cipher

Password hashing and encryption library for the janet programming language
MIT License
8 stars 1 forks source link

cipher

Hash passwords and encrypt strings with janet

Install

Add to your project.janet file

{:dependencies ["https://github.com/joy-framework/cipher"]}

Use

Libhydrogen requires a master key for all hashing/encryption functions, so the first step is to generate it

(import cipher)

(def key (cipher/password-key))

Now we can use that key when hashing a password

(def hashed-password (cipher/hash-password key "correct horse battery staple"))

This returns a garbled string that represents the password. Then to verify a plaintext password you call this

(cipher/verify-password key hashed-password "correct horse battery staple")

This returns either true or false.

Encryption

You can also encrypt strings!

(let [key (cipher/encryption-key)]
  (as-> "hello" ?
        (cipher/encrypt key ?)
        (cipher/decrypt key ?))) => "hello"

Generic hashing

(cipher/hash "hello") => "7fde0696c922ba4e1348dd7fa32f957531b861a93d78eef120a6c1a62fa3d2df"

Test

Run jpm test from the project folder.