# Porting node.js encryption function to Elixir

**URL:** <https://forum.elixirforum.com/t/porting-node-js-encryption-function-to-elixir/39493>\
**Category:** Questions\
**Tags:** crypto\
**Created:** [May 7, 2021, 8:52pm UTC](https://forum.elixirforum.com/t/porting-node-js-encryption-function-to-elixir/39493 "2021-05-07T20:52:45Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![hauleth](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/hauleth/32/18942_2.png) [@hauleth](https://forum.elixirforum.com/u/hauleth)\
**Post date:** [May 24, 2021, 8:35am UTC](https://forum.elixirforum.com/t/porting-node-js-encryption-function-to-elixir/39493/10 "2021-05-24T08:35:11Z")

</div>

> [@mattbaker](#):
>
> Something like `aes_256_cbc` is fine as far as I know

Please, do not do that. Encryption without authentication is pointless as attacker can manipulate the plaintext without any problems (without knowing the plaintext):

```elixir
iex> key = :crypto.strong_rand_bytes(32)
iex> <<a, rest::binary>> = iv = :crypto.strong_rand_bytes(16)
iex> plaintext = "Abba"
iex(46)> iv1 = Bitwise.bxor(a, 3) <> rest
iex(47)> ct = :crypto.crypto_one_time(:aes_256_cbc, key, iv, plaintext, encrypt: true, padding: :pkcs_padding)
iex(48)> :crypto.crypto_one_time(:aes_256_cbc, key, iv1, ct, encrypt: false, padding: :pkcs_padding)
"Bbba"

```

So as you can see, I can change first letter from `A` to `B` without any problems. This is **huge** problem as you no longer can trust the cipher text.

In short - do not use non-AEAD ciphers, never.

---

_[View the full topic](https://forum.elixirforum.com/t/porting-node-js-encryption-function-to-elixir/39493)._
