SimpleCrypto (simple_crypto v1.0.1) 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 char
, 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
Decrypts str
using key
as the decryption key.
Examples
iex> SimpleCrypto.decrypt("qCgs4rfReY5nTX39uHwjww==", "secret key")
"Hi there"
Specs
Encrypts str
using key
as the encryption key.
Examples
iex> SimpleCrypto.encrypt("Hi there", "secret key")
"qCgs4rfReY5nTX39uHwjww=="
Specs
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(non_neg_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"
Specs
otp_rand_str(non_neg_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"
Specs
pad(iodata(), non_neg_integer(), iodata()) :: binary()
Pad the end of str
using char
, so that the total length is length
.
Examples
iex> SimpleCrypto.pad("123", 8, ".")
"123....."
Specs
rand_int_str(non_neg_integer()) :: binary()
Generate a random string of length
length, consisting only of integers.
Examples
iex> SimpleCrypto.rand_int_str(6)
"811238"
Specs
rand_str(non_neg_integer()) :: binary()
Generate a random string of length
length.
Examples
iex> SimpleCrypto.rand_str(32)
"rvbAtDMdVPJu2J-QDyAxgOLAL0LQWL0w"
Specs
Hashes str
using the SHA256 algorithm.
Examples
iex> SimpleCrypto.sha256("Turn me into SHA256")
"87A3AABED406EFBCD4956E2E32E75948DB88E7ED35CACD4D8B66669EA849C102"