ESC
Type to search...
S
Soli Docs

Cryptography Functions

Password hashing with Argon2, X25519 key exchange, Ed25519 signatures.

Password Hashing

argon2_hash(password)

Hash a password using Argon2id (recommended algorithm). Also available as password_hash.

Parameters

password : String - The plain text password to hash

Returns

String - The Argon2id hash string
let hash = argon2_hash("secretpassword")
// $argon2id$v=19$m=19456,t=2,p=1$...
argon2_verify(password, hash)

Verify a password against an Argon2id hash. Also available as password_verify.

Parameters

password : String - The plain text password to verify
hash : String - The stored hash to verify against

Returns

Bool - true if password matches, false otherwise
if argon2_verify(user_input, stored_hash) {
    println("Password correct!")
} else {
    println("Invalid password")
}

X25519 Key Exchange

x25519_keypair()

Generate an X25519 key pair for Diffie-Hellman key exchange.

Returns

Hash - { "private": String, "public": String }
let keypair = x25519_keypair()
println(keypair["public"])   // Base64 public key
println(keypair["private"])  // Base64 private key
x25519_shared_secret(private_key, public_key)

Compute a shared secret from your private key and another party's public key.

let alice = x25519_keypair()
let bob = x25519_keypair()

// Both compute the same shared secret
let alice_secret = x25519_shared_secret(alice["private"], bob["public"])
let bob_secret = x25519_shared_secret(bob["private"], alice["public"])
// alice_secret == bob_secret

Ed25519 Signatures

ed25519_keypair()

Generate an Ed25519 signing key pair for digital signatures.

Returns

Hash - { "private": String, "public": String }
let keypair = ed25519_keypair()
// Use keypair["private"] to sign messages
// Share keypair["public"] for verification