-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added is_decryped and working on documentation
- Loading branch information
Showing
5 changed files
with
54 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
/deps | ||
erl_crash.dump | ||
*.ez | ||
docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,41 @@ | ||
defmodule Safetybox do | ||
|
||
@moduledoc """ | ||
# Safetybox a collection of security oriented functions | ||
## Dependency | ||
{ :safetybox, "~> 0.1" } | ||
## Usage | ||
### API | ||
pwd = Safetybox.encrypt("helloworld") | ||
Safetybox.is_decrypted("goodbyeworld", pwd) # > returns false | ||
Safetybox.is_decrypted("helloworld", pwd) # > returns true | ||
## Author | ||
Copyright © 2014 Andrew Forward | ||
@a4word, [email protected] | ||
Licensed under MIT. | ||
""" | ||
|
||
# Taken from https://gist.github.com/10nin/5713366 | ||
def encrypt(nil), do: encrypt("") | ||
def encrypt(str) do | ||
:crypto.hash(:md5, str) | ||
|
||
@doc """ | ||
Convert a plaintext string into an encrypted string, for example | ||
Safetybox.encrypt("helloworld") | ||
""" | ||
def encrypt(plaintext) do | ||
:crypto.hash(:md5, plaintext) | ||
|> :erlang.bitstring_to_list | ||
|> Enum.map(&(:io_lib.format("~2.16.0b", [&1]))) | ||
|> List.flatten | ||
|> :erlang.list_to_bitstring | ||
end | ||
|
||
@doc """ | ||
Compare a plaintext string to it's encrypted version to test if they match. | ||
Safetybox.is_decrypted("helloworld", "dasdf!@#CASD") | ||
""" | ||
def is_decrypted(plaintext, encrypted), do: encrypt(plaintext) == encrypted | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
%{"earmark": {:hex, :earmark, "0.1.12"}, | ||
"ex_doc": {:hex, :ex_doc, "0.6.2"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters