Functions for generating cryptographic hashes and tokens.
Provides utilities to generate random cryptographic values including MD5, SHA-1, SHA-256, SHA-512 hashes, UUID v4 identifiers, and secure random tokens.
Summary
Functions
Generates a random hash for the given algorithm.
Generates a random MD5 hash.
Generates a random SHA-1 hash.
Generates a random SHA-256 hash.
Generates a random SHA-512 hash.
Generates a random secure token.
Generates a random UUID v4 string.
Functions
Generates a random hash for the given algorithm.
A convenience dispatcher over md5/1, sha1/1, sha256/1, and sha512/1, selected
by the type parameter, which must be one of :md5, :sha1, :sha256, or :sha512.
Options
:case(:loweror:upper) - the output character case. Defaults to:lower.
Examples
iex> NeoFaker.Crypto.hash(:md5)
"afc4c626c55e4166421d82732163857d"
iex> NeoFaker.Crypto.hash(:sha256, case: :upper)
"E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855"
Generates a random MD5 hash.
MD5 produces a 128-bit (32 hexadecimal character) hash value.
Options
:case(:loweror:upper) - the output character case. Defaults to:lower.
Examples
iex> NeoFaker.Crypto.md5()
"afc4c626c55e4166421d82732163857d"
iex> NeoFaker.Crypto.md5(case: :upper)
"AFC4C626C55E4166421D82732163857D"
Generates a random SHA-1 hash.
SHA-1 produces a 160-bit (40 hexadecimal character) hash value.
Options
:case(:loweror:upper) - the output character case. Defaults to:lower.
Examples
iex> NeoFaker.Crypto.sha1()
"356a192b7913b04c54574d18c28d46e6395428ab"
iex> NeoFaker.Crypto.sha1(case: :upper)
"356A192B7913B04C54574D18C28D46E6395428AB"
Generates a random SHA-256 hash.
SHA-256 produces a 256-bit (64 hexadecimal character) hash value.
Options
:case(:loweror:upper) - the output character case. Defaults to:lower.
Examples
iex> NeoFaker.Crypto.sha256()
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
iex> NeoFaker.Crypto.sha256(case: :upper)
"E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855"
Generates a random SHA-512 hash.
SHA-512 produces a 512-bit (128 hexadecimal character) hash value.
Options
:case(:loweror:upper) - the output character case. Defaults to:lower.
Examples
iex> NeoFaker.Crypto.sha512()
"cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"
iex> NeoFaker.Crypto.sha512(case: :upper)
"CF83E1357EEFB8BDF1542850D66D8007D620E4050B5715DC83F4A921D36CE9CE47D0D13C5D85F2B0FF8318D2877EEC2F63B931BD47417A81A538327AF927DA3E"
@spec token(pos_integer(), keyword()) :: String.t()
Generates a random secure token.
Returns a URL-safe random token string suitable for API keys, session tokens,
and similar secrets. The length parameter controls the number of random bytes
used, not the final string length (which varies by encoding). Defaults to 32.
Options
:encoding(:base64or:hex) - the output encoding.:base64is URL-safe. Defaults to:base64.
Examples
iex> NeoFaker.Crypto.token()
"dGVzdF90b2tlbl9oZXJl"
iex> NeoFaker.Crypto.token(32, encoding: :hex)
"a1b2c3d4e5f6708192a3b4c5d6e7f8091a2b3c4d5e6f7081"
Generates a random UUID v4 string.
Options
:format(:standardor:compact) -:standardincludes dashes,:compactomits them. Defaults to:standard.:case(:loweror:upper) - the output character case. Defaults to:lower.
Examples
iex> NeoFaker.Crypto.uuid()
"550e8400-e29b-41d4-a716-446655440000"
iex> NeoFaker.Crypto.uuid(format: :compact)
"550e8400e29b41d4a716446655440000"
iex> NeoFaker.Crypto.uuid(case: :upper)
"550E8400-E29B-41D4-A716-446655440000"