This problem is most easily understood by reading my attached Gist: https://gist.github.com/KazW/e77e5c7603d7700d86c1
I have a simple encryption / decryption function in Ruby that works. Each time the encryption function is executed, a new initialization vector is created with OpenSSL::Random.random_bytes(12)
. When I try to follow the same steps in Elixir using :crypto.strong_rand_bytes(12)
, it generates an IV that can be used for encryption, but decryption fails.
Stranger, if I use Ruby-generated IV and use it for encryption in Elixir. When transmitting encrypted text for decryption to Elixir, the decryption function returns plain text without errors. I investigated the algorithm used, IV should be a random byte, an important factor is the number of bytes in it (12).
My initial thought is that maybe I'm calling the wrong OpenSSL method to generate IV. However, I could not find any information about what the correct method would be.
source
share