SimpleCrypto (simple_crypto v1.0.2) View Source

Simple crypto helpers for Elixir.

Link to this section Summary

Functions

Decrypts str using key as the decryption key.

Encrypts str using key as the encryption key.

Use key to generate a hash value of str using the HMAC method.

Generate a random string of length length that is suitable to use as an easily copy/pastable ID (no hyphens or other problematic characters).

Generate a random string of length length that is suitable to use as OTP codes.

Pad the end of str using padding, so that the total length is length.

Generate a random string of length length, consisting only of integers.

Generate a random string of length length.

Hashes str using the SHA256 algorithm.

Link to this section Functions

Specs

decrypt(iodata(), iodata()) :: binary()

Decrypts str using key as the decryption key.

Examples

iex> SimpleCrypto.decrypt("qCgs4rfReY5nTX39uHwjww==", "secret key")
"Hi there"

Specs

encrypt(iodata(), iodata()) :: binary()

Encrypts str using key as the encryption key.

Examples

iex> SimpleCrypto.encrypt("Hi there", "secret key")
"qCgs4rfReY5nTX39uHwjww=="

Specs

hmac(iodata(), iodata()) :: binary()

Use key to generate a hash value of str using the HMAC method.

Examples

iex> SimpleCrypto.hmac("HMAC me now!", "secret key")
"E7235176D81E29EC202B117324C7B3A2A6180F2A2A163D79E5A6BB58E7A61A7B"

Specs

id_rand_str(pos_integer()) :: binary()

Generate a random string of length length that is suitable to use as an easily copy/pastable ID (no hyphens or other problematic characters).

Examples

iex> SimpleCrypto.id_rand_str(12)
"SWm6fDWvd4id"
Link to this function

otp_rand_str(length \\ 16)

View Source

Specs

otp_rand_str(pos_integer()) :: binary()

Generate a random string of length length that is suitable to use as OTP codes.

Examples

iex> SimpleCrypto.otp_rand_str(16)
"UXGMUXNUANHONKZR"
Link to this function

pad(str, length \\ 16, padding \\ " ")

View Source

Specs

pad(iodata(), pos_integer(), iodata()) :: binary()

Pad the end of str using padding, so that the total length is length.

Examples

iex> SimpleCrypto.pad("123", 8, ".")
"123....."
Link to this function

rand_int_str(num_of_digits)

View Source

Specs

rand_int_str(pos_integer()) :: binary()

Generate a random string of length length, consisting only of integers.

Examples

iex> SimpleCrypto.rand_int_str(6)
"811238"

Specs

rand_str(pos_integer()) :: binary()

Generate a random string of length length.

Examples

iex> SimpleCrypto.rand_str(32)
"rvbAtDMdVPJu2J-QDyAxgOLAL0LQWL0w"

Specs

sha256(iodata()) :: binary()

Hashes str using the SHA256 algorithm.

Examples

iex> SimpleCrypto.sha256("Turn me into SHA256")
"87A3AABED406EFBCD4956E2E32E75948DB88E7ED35CACD4D8B66669EA849C102"