Packard_Goose

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

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

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

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

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).

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New

Other popular topics Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44778 311
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New

We're in Beta

About us Mission Statement