openssl cmd line AES encrypt iv and key accept only hex format!!!

如下所示, iv 和 key 的 size 都是 128bit (16 byte),但是需要转换成十六进制传入 openssl 命令行参数:

echo -ne "Hello, World!" | openssl aes-128-cbc -e -K 01010101010101010101010101010101 -iv 02020202020202020202020202020202 > enc3.dat
cat ./enc3.dat | hexdump -C

换成 c++ std::string:

  std::string key = "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01";
  std::string iv = "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02";

另外 aes-128-cbc 加解密的 key 大小为 16 byte, aes-256-cbc 的key 大小为 32 byte.
他们的 iv 都应该是 16个 byte(加密的block大小)。

你可能感兴趣的:(linux常用命令,openssl,AES加密)