Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/argon2/cli/deps.ts>argon2.hash

Argon2 encryption library for Deno
Latest
function argon2.hash
import { argon2 } from "https://deno.land/x/argon2@v0.9.2/cli/deps.ts";
const { hash } = argon2;

Hash a string.

console.log(await hash("test"));
// $argon2i$v=19$m=4096,t=3,p=1$rboCX6NY3Yh26iEzgKEmWA$daswToHMDCu94YHLk1a8Bhy9THuTJkA9fTA6QdCTqkc

The above command hash the password bla bla bla.

You can tweak the time spent and the output hash adding custom options:

let salt = crypto.getRandomValues(new Uint8Array(Math.max(8, Math.random() * 32)));
let secret = encode("my-super-secret")
console.log(await hash("test", {
  salt,
  secret,
  variant: Variant.Argon2id,
  version: Version.V13,
  memoryCost: 8192,
  timeCost: 10,
  threadMode: ThreadMode.Parallel,
  lanes: 4,
  data: {
    hashedAt: Date.now(),
    requestId: "a00d22c0-4681-4351-8c8f-6f02a42dd941"
  }
}));

// $argon2id$v=19$m=8192,t=10,p=4$HjLMjlAq6MY$UU9Xv8JTZy01Tlfr1rBF0Ql7quTHdwoQOjDwu5A9AOE

Parameters

password: string

A String value we want to hash.

optional
options: Partial<HashOptions> = [UNSUPPORTED]

A Uint8Array of minimum size of 8 used as salt.