CharlesO
Please can you provide or point to replacement code for:
crypto — crypto v5.5 (erlang.org)
from here: Deprecations — Erlang/OTP v27.0.1
It seems several functions have no equivalents.
Functions Deprecated in OTP 27
code:lib_dir/2 (this functionality will be removed in a future release)
crypto:private_decrypt/4 (do not use)
crypto:private_encrypt/4 (use public_key:sign/3 instead)
crypto:public_decrypt/4 (use public_key:verify/4 instead)
crypto:public_encrypt/4 (do not use)
mnesia_registry:create_table/_ (use mnesia:create_table/2 instead)
public_key:decrypt_private/2 (do not use)
public_key:decrypt_private/3 (do not use)
public_key:decrypt_public/2 (use public_key:verify/4 instead)
public_key:decrypt_public/3 (use public_key:verify/5 instead)
public_key:encrypt_private/2 (use public_key:sign/3 instead)
public_key:encrypt_private/3 (use public_key:sign 4 instead)
public_key:encrypt_public/2 (do not use)
public_key:encrypt_public/3 (do not use)
ssl:prf/5 (Use export_key_materials/4 instead. Note that in OTP 28 the 'testing' way of calling this function will no longer be supported.)
I have been trying to redo : raw.githubusercontent.com/WhatsApp/WhatsApp-Flows-Tools/refs/heads/main/examples/endpoint/nodejs/basic/src/encryption.js
For a project but the samples are all coming back with depreciated functions. (Even ChatGPT and Copilot return incorrect code)
here is my effort so far:
defmodule Flows do
defmodule FlowEndpointException do
defexception [:message, :status_code]
@impl true
def exception({status_code, message}) do
%__MODULE__{message: message, status_code: status_code}
end
end
def decrypt_request(body, private_pem, passphrase) do
%{
"encrypted_aes_key" => encrypted_aes_key,
"encrypted_flow_data" => encrypted_flow_data,
"initial_vector" => initial_vector
} = body
private_key = :public_key.pem_entry_decode({:RSAPrivateKey, private_pem, passphrase})
try do
decrypted_aes_key =
encrypted_aes_key
|> Base.decode64!()
|> :crypto.decrypt(:rsa, private_key, [
{:rsa_padding, :rsa_pkcs1_oaep_padding},
{:rsa_oaep_md, :sha256}
])
flow_data_buffer = Base.decode64!(encrypted_flow_data)
initial_vector_buffer = Base.decode64!(initial_vector)
tag_length = 16
{encrypted_flow_data_body, encrypted_flow_data_tag} =
:erlang.split_binary(flow_data_buffer, byte_size(flow_data_buffer) - tag_length)
decrypted_json_string =
:crypto.crypto_one_time_aead(
:aes_128_gcm,
decrypted_aes_key,
initial_vector_buffer,
encrypted_flow_data_body,
"",
encrypted_flow_data_tag,
false
)
{
:ok,
%{
decrypted_body: Jason.decode!(decrypted_json_string),
aes_key_buffer: decrypted_aes_key,
initial_vector_buffer: initial_vector_buffer
}
}
rescue
_ ->
raise FlowEndpointException,
{421, "Failed to decrypt the request. Please verify your private key."}
end
end
def encrypt_response(response, aes_key_buffer, initial_vector_buffer) do
flipped_iv = for <<byte <- initial_vector_buffer>>, do: Bitwise.bnot(byte)
{cipher_text, cipher_tag} =
:crypto.crypto_one_time_aead(
:aes_128_gcm,
aes_key_buffer,
flipped_iv,
Jason.encode!(response),
"",
16,
true
)
Base.encode64(cipher_text <> cipher_tag)
end
end
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
Hello,
I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex











Marked As Solved- Show Best Posts
- Show All Posts (oldest first)
- Show All Posts (newest first)
voltone
Those deprecations have been reverted in OTP 27.1.
Also Liked
Schultzer
Working with crypto without any fundamental understanding is a recipe for disaster, even expert gets this wrong.
First you’ll need to understand why things have been deprecated, and what would be an alternative, if any.