Packard_Goose
How to encrypt file
How would I go about attempting to encrypt a file in elixir? I need to store some sensitive information in a text file such as a .dat but the information can only be decrypted if you have the passphrase to unlock the contents of the file. I’ve tried looking at :crypto but I don’t really understand it.
This answer seems to be what I’m looking for but I don’t know if it really does what I want it to. I would simply use Base.decode64(:crypto.block_decrypt(:aes_ecb, key, input)) to decrypt the data?
Marked As Solved
voltone
Found the code, cleaned it up a bit and published a v0.1.0:
There is room for improvements, but it successfully decrypts files created by the Linux CLI version of eascrypt, and vice versa.
Also Liked
voltone
Please beware that AES Crypt is not quite a substitute for a tool like GPG. Don’t use it for highly sensitive data, just for ‘casual protection’.
It does implement key wrapping, unlike other file encryption packages I saw on Hex, but the KDF is proprietary and relatively weak by today’s standards, possibly enabling brute force attacks on modern hardware. Make sure you use strong passwords to limit that risk.
I could add support for PBKDF2, but that would break interoperability with other tools.
hubertlepicki
I would go with GnuPG (Gnu Privacy Guard, https://www.gnupg.org/), possibly calling it directly from the command line, or use some wrapper. Googling found this GitHub - rozap/exgpg: gpg interface · GitHub which does not look maintained but it may work, or give you idea how to call the tool.
I use GnuPG for stuff like encrypting backup files from shell scripts and it is outstanding.
hauleth
If you do not understand crypto module, then don’t implement encrypting files on your own, because it is almost 100% sure that you will do something wrong (like using ECB mode, which you did in your example). Do as @hubertlepicki said and use external tools that do this for longer, they do it better, and have broader knowledge of cryptography (and even despite that they sometimes do something in the wrong way).
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #code-sync
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








