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

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
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
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement