I took the time to test your code and the problem is really simple. If you do echo "Bonjour" > test.txt
a "linefeed" is automatically added to Bonjour
.
So in Java you encrypt the string "Bonjour"
but the text.txt
file read by openssl contains the string "Bonjour\n"
. You can change that by adding the -n
flag to echo
. Now openssl should print the same as Java:
$ echo -n "Bonjour" > test.txt
$ openssl enc -aes128 -a -in test.txt -K 15577737BBD910E794A6B3C250678DAF -iv 0
NkrWPLgiY0rt34iaNzhjOg==
Obviously my statement that the IV is randomly generated by Java is wrong.