Search code examples
dependencieselixirelixir-mix

ExCrypto on OTP 24


The application is upgraded to run elixir 1.12.2 and uses OTP 24 and I have confirmed these are the versions running.

When running some tests I get the following error:

** (UndefinedFunctionError) function :crypto.block_encrypt/4 is undefined or private, use crypto:crypto_one_time/5, crypto:crypto_one_time_aead/6,7 or crypto:crypto_(dyn_iv)?_init + crypto:crypto_(dyn_iv)?_update + crypto:crypto_final instead

Most of the googling I have done suggested upgrading plug_crypto to version 1.2.2, which has been done.

This function block_encrypt/4 is underlying Erlang code and the line which calls block_encrypt/4 in my Elixir code is:

ExCrypto.encrypt(content_key, "", content_json)

I found a PR for ExCrytpo which is supposed to fix this: https://github.com/ntrepid8/ex_crypto/pull/40

Someone left a comment asking if the code needs to be pushed to hex.pm, and wondering if it's possible this code wasn't released to hex.pm yet?


Solution

  • Yes, it seems that ExCrypto has not published the release containing the changes in that PR to Hex yet. The latest version on hex is 0.10.0, was released on Feb 20, 2019. The PR was merged on May 27, 2021.

    As a workaround, you could use the git repository as the source of the dependency, rather than Hex:

    {:ex_crypto, git: "https://github.com/ntrepid8/ex_crypto.git", branch: "master"}
    

    It might be a good idea to pin to the specific commit, rather than the master branch:

    {:ex_crypto,
     git: "https://github.com/ntrepid8/ex_crypto.git",
     ref: "0915c274503f9fc6d6f5fab8c98467e7414cf8fc"}
    

    Another (probably better) option is that you could remove your dependency on ExCrypto by updating your code to use the Erlang :crypto library directly.