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 verifyhash : String - The stored hash to verify againstReturns
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
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