Hi everyone.
I’m currently looking into AES256 CBC and how to encrypt/decrypt plaintext using Elixir. The Erlang crypto module provides the crypto_one_time/5 function which seems like the right function to use.
https://www.erlang.org/docs/28/apps/crypto/crypto#crypto_one_time/5
The code I used:
iv = :crypto.strong_rand_bytes(16)
key = :crypto.strong_rand_bytes(32)
data_to_encrypt = "the_plaintext"
:crypto.crypto_one_time(:aes_256_cbc, key, iv, data_to_encrypt, true)
The problem I’m facing is that the crypto_one_time/5 function returns an empty string.
crypto.info/1 returns:
:crypto.info
%{
otp_crypto_version: ~c"5.5.1",
compile_type: :normal,
link_type: :dynamic,
cryptolib_version_compiled: ~c"OpenSSL 3.3.2 3 Sep 2024",
cryptolib_version_linked: ~c"OpenSSL 3.4.0 22 Oct 2024",
fips_provider_available: false
}
aec_256_cbc gets listed when using :crypto.supports()
:crypto.supports[:ciphers]
[:chacha20, :aes_256_ofb, :aes_192_ofb, :aes_128_ofb, :sm4_ctr, :sm4_ofb,
:sm4_cfb, :sm4_ecb, :sm4_cbc, :blowfish_ecb, :blowfish_ofb64, :blowfish_cfb64,
:blowfish_cbc, :des_ede3_cfb, :des_ecb, :des_cfb, :des_cbc, :rc4, :rc2_cbc,
:aes_128_cbc, :aes_192_cbc, :aes_256_cbc, :aes_128_cfb128, :aes_192_cfb128,
:aes_256_cfb128, :aes_128_cfb8, :aes_192_cfb8, :aes_256_cfb8, :aes_128_ecb,
:aes_192_ecb, :aes_256_ecb, :sm4_gcm, :sm4_ccm, :chacha20_poly1305,
:aes_256_gcm, :aes_256_ccm, :aes_192_gcm, :aes_192_ccm, :aes_128_gcm,
:aes_128_ccm, :aes_256_ctr, :aes_192_ctr, :aes_128_ctr, :des_ede3_cbc,
:aes_cbc, :aes_ccm, :aes_cfb128, :aes_cfb8, :aes_ctr, :aes_ecb, ...]
Any help would be greatly appreciated.