SimpleCrypto (simple_crypto v1.0.9) 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.
Use key to generate a base64-encoded 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 an OTP (One-time pad) code.
DEPRECATED: Use pad_by_width/3 instead.
Pad the end of str using padding, so that the total length becomes a multiple of width.
Generate a random string of length length, consisting only of integers.
Generate a random string of length length.
Hashes str using the SHA256 algorithm.
Hashes str using the SHA256 algorithm, then base64-encodes it.
Link to this section Functions
Specs
Decrypts str using key as the decryption key.
Example
iex> SimpleCrypto.decrypt("qCgs4rfReY5nTX39uHwjww==", "secret key")
"Hi there"
Specs
Encrypts str using key as the encryption key.
Example
iex> SimpleCrypto.encrypt("Hi there", "secret key")
"qCgs4rfReY5nTX39uHwjww=="
Specs
Use key to generate a hash value of str using the HMAC method.
Example
iex> SimpleCrypto.hmac("HMAC me now!", "secret key")
"E7235176D81E29EC202B117324C7B3A2A6180F2A2A163D79E5A6BB58E7A61A7B"
Specs
Use key to generate a base64-encoded hash value of str using the HMAC method
Example
iex> SimpleCrypto.hmac_base64("HMAC and base64 me now!", "secret key")
"Xqsja2bp+jfleCkl4bRFZoyljM2RL0DC4PNBkTtKXrk="
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).
Example
iex> SimpleCrypto.id_rand_str(12)
"SWm6fDWvd4id"
Specs
otp_rand_str(pos_integer()) :: binary()
Generate a random string of length length that is suitable to use as an OTP (One-time pad) code.
Example
iex> SimpleCrypto.otp_rand_str(16)
"UXGMUXNUANHONKZR"
Specs
pad(iodata(), pos_integer(), iodata()) :: binary()
DEPRECATED: Use pad_by_width/3 instead.
Specs
pad_by_width(iodata(), pos_integer(), iodata()) :: binary()
Pad the end of str using padding, so that the total length becomes a multiple of width.
Example
iex> SimpleCrypto.pad_by_width("The length of this string is 76 before padding, 4 less than a multiple of 16", 16, ".")
"The length of this string is 76 before padding, 4 less than a multiple of 16...."
Specs
rand_int_str(pos_integer()) :: binary()
Generate a random string of length length, consisting only of integers.
Example
iex> SimpleCrypto.rand_int_str(6)
"811238"
Specs
rand_str(pos_integer()) :: binary()
Generate a random string of length length.
Example
iex> SimpleCrypto.rand_str(32)
"rvbAtDMdVPJu2J-QDyAxgOLAL0LQWL0w"
Specs
Hashes str using the SHA256 algorithm.
Example
iex> SimpleCrypto.sha256("Turn me into SHA256")
"87A3AABED406EFBCD4956E2E32E75948DB88E7ED35CACD4D8B66669EA849C102"
Specs
Hashes str using the SHA256 algorithm, then base64-encodes it.
Example
iex> SimpleCrypto.sha256_base64("Turn me into base64-encoded SHA256")
"/UWKWh0NJFgCf3mWSIJiDuJA9HCY94T2l/XJ+CyreAM="