AES-CBC 的 OpenSSL 实现要求 IV 的大小与块大小相同 - 即在您的情况下为 128 位。enc
手册页说:
-iv IV
the actual IV to use: this must be represented as a string comprised only of hex digits.
它没有说,如果在命令行上给出的 IV 更短,那么如何获得所有 128 位 - 就像在您的示例命令中一样。
幸运的是 OpenSSL 的源代码是可用的。我们可以看到enc.c
IV 被初始化为全零,然后从命令行参数填充起始字节:
[hiv is the value of the command-line option -iv:]
if ((hiv != NULL) && !set_hex(hiv, iv, sizeof iv)) {
BIO_printf(bio_err, "invalid hex iv value\n");
[...]
int set_hex(char *in, unsigned char *out, int size)
{
int i, n;
unsigned char j;
n = strlen(in);
if (n > (size * 2)) {
BIO_printf(bio_err, "hex string is too long\n");
return (0);
}
memset(out, 0, size);
for (i = 0; i < n; i++) {
.......
所以,你正在做的事情——只为“-iv”提供一个零——恰好产生了你需要的全零 IV。
请注意,使用常量——尤其是“典型”,例如全零——IV 是一种不好的安全做法;维基百科文章解释了原因。