更新时间:2023-01-18 09:15:22
两种方式都可以正常工作,但是你加密的是不同的东西.
Both ways are working correctly, however you are encrypting different things.
此处的字符串语法 (<<<
) 在字符串中添加换行符.所以Java输出是加密a"的结果,命令行输出是加密a
"的结果(即字符a
后跟换行符).
The here string syntax (<<<
) adds a newline to the string. So the Java output is the result of encrypting "a", and the command line output is the result of encrypting "a
" (i.e. the character a
followed by a newline).
从命令行试试这个:
printf "a" | /usr/bin/openssl enc -aes-256-cbc -base64 -K "b38b730d4cc721156e3760d1d58546ce697adc939188e4c6a80f0e24e032b9b7" -iv "064df9633d9f5dd0b5614843f6b4b059"
结果是 VTUOJJp38Tk+P5ikR4YLfw==
,与您的 Java 结果匹配.
the result is VTUOJJp38Tk+P5ikR4YLfw==
, matching your Java result.