dwyl/phoenix-ecto-encryption-example

Use new :crypto API

wuhkuh opened this issue ยท 6 comments

According to the :crypto documentation block_encrypt and block_decrypt are old and should not be used in new applications. We should consider updating the encryption functions to the new API.

@wuhkuh great suggestion! Thank you for taking time to open this issue.

"not deprecated for now, but may be in a future release":
image

If anyone has interest/time to update the tutorial, it would be very much appreciated. ๐Ÿ‘

@NikitaAvvakumov kindly created the PR: #23 to update the :crypto syntax in the README.md
we need to update it in the code

:crypto.block_encrypt(:aes_gcm, key, iv, {@aad, to_string(plaintext), 16})

and bump the Erlang version in .travis.yml to 22 so that the build will actually pass:

Using Erlang 23+

For encryption:

{ciphertext, tag} = :crypto.crypto_one_time_aead(:aes_gcm, key, iv, to_string(plaintext), @aad, true)

For decryption:

:crypto.crypto_one_time_aead(:aes_gcm, get_key(), iv, ciphertext, @aad, tag, false)

gets the tests passing :)

Sweet. thanks @plicjo โญ

Included in #47