Spent quite a bit of time pondering this as I am unable to get the desired output similar to the PHP function that im trying to duplicate:
plaintext = ["<foo>","'bar'","\"baz\"","&blong&"] |> Jason.encode!
key = "secreted"
iv = "PlayerAZ"
:crypto.crypto_one_time(:des_cbc, key, iv, plaintext, [{:encrypt, :true},{:padding, :pkcs_padding}] ) |> Base.encode64
PHP:
<?php
$plaintext = json_encode(array('<foo>',"'bar'",'"baz"','&blong&'));
$key = 'secreted';
$vector = 'PlayerAZ';
$encryptedString = openssl_encrypt($plaintext, 'des-cbc', $key, OPENSSL_RAW_DATA, $vector);
echo 'Encrypted: '.$encryptedString."\n";
echo ''.$plaintext."\n";
$encryptedStringBase64 = base64_encode($encryptedString);
echo 'Encrypted + base 64:'.$encryptedStringBase64."\n";
echo 'Decrypted:'.openssl_decrypt(base64_decode($encryptedStringBase64),'des-cbc', $key, OPENSSL_RAW_DATA, $vector)."\n";
Sandbox: https://wtools.io/php-sandbox/b8Xw
In both cases: the output is the same for both: βrQnm2tysllww+bZLSwOa9UQUc0EEH3sNlu84k5o33VgbmbnHnIZx0g==β
The problem when i change the plaintext variable to include unicode character, β\xc3\xa9β as follows:
array(ββ,"βbarβ",ββbazββ,β&blong&β, β\xc3\xa9β (PHP)
["","βbarβ","βbazβ","&blong&","\xc3\xa9"] (Elixir)
Both function outputs diverge and no longer agree.
May I know what am i doing wrong? Thanks.