fnux

fnux

[Solved] :crypto.block_encrypt/decrypt - symmetric?

Hello !

I was expecting :crypto.block_encrypt :aes_ige256 to be symmetric, I don’t get what’s wrong. Can someone enlighten me ?

Here is an example script :

data = <<666::size(256)-unit(8)>>
tmp_aes_key = <<1234567890::size(32)-unit(8)>>
tmp_aes_iv = <<0987654321::size(32)-unit(8)>>

encrypted = :crypto.block_encrypt :aes_ige256, tmp_aes_key, tmp_aes_iv, data
decrypted = :crypto.block_decrypt :aes_ige256, tmp_aes_key, tmp_aes_iv, data

IO.puts "-- Initial Data --"
IO.inspect data
IO.puts "-- Encrypted --"
IO.inspect encrypted
IO.puts "-- Decrypted --"
IO.inspect decrypted

And its output :

-- Initial Data --
<<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...>>
-- Encrypted --
<<13, 146, 170, 197, 88, 244, 100, 48, 180, 234, 28, 168, 36, 10, 88, 225, 15,
  232, 33, 201, 90, 37, 54, 105, 155, 70, 166, 40, 128, 12, 107, 11, 234, 61,
  80, 202, 89, 18, 222, 125, 127, 133, 98, 236, 28, 107, 254, 155, 130, 223,
  ...>>
-- Decrypted --
<<200, 243, 4, 223, 10, 44, 240, 101, 171, 77, 103, 159, 39, 239, 138, 91, 108,
  248, 162, 162, 228, 170, 138, 113, 98, 56, 248, 183, 167, 19, 123, 243, 162,
  144, 214, 253, 136, 98, 37, 210, 14, 108, 56, 31, 33, 222, 148, 228, 183, 8,
  ...>>

Thanks !

Marked As Solved

OvermindDL1

OvermindDL1

Shouldn’t data here be encrypted?

Also Liked

OvermindDL1

OvermindDL1

Hehe, happens to us all. ^.^

Also you can click the checkmark on a post to mark that post as the one that resolves the issue. :slight_smile:

fnux

fnux

Ow, my bad. tired

slouchpie

slouchpie

For posterity: don’t use :crypto.block_encrypt for anything new you are writing.

Instead, use :crypto:crypto_one_time.

See here for info: New and Old API — OTP 29.0.2 (crypto 5.9)

Where Next?

Popular in Questions Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
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
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
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
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

We're in Beta

About us Mission Statement