OpenSSL 在 aes 加密中填充密钥?

OpenSSL pads keys in aes encryption?

我正在尝试对 openssl 使用 aes-128-cbc 加密,我希望密钥需要是 32 位数字。但是,我注意到当我输入长度为 18 的密钥时,openssl 不会给我一个错误。

echo hello | openssl enc -aes-128-cbc -A -a -nosalt -K 123456789012345678 -iv 66666666666666666666666666666666

output:zBN+65infn74QK+prfY6kw==

但是如果我在密钥后面加0直到它是32位数字,我仍然得到相同的结果。

echo hello | openssl enc -aes-128-cbc -A -a -nosalt -K 12345678901234567800000000000000 -iv 6666666666666666666666666666666

output:zBN+65infn74QK+prfY6kw==

是否有说明 OpenSSL 向键添加填充的文档?

编辑:我需要在代码中重现此行为。我得到了密钥,但无法保证密钥的位数。

具有 128 位密钥的 AES 是 16 字节或 32 位十六进制数字密钥。它可能是零填充键的未指定部分,不依赖键填充,这是未指定的行为。

最好始终为加密函数提供准确大小的输入,为 AES 128 位密钥指定 32 个十六进制数字。

现在,如果您的密钥或 IV 太短,OpenSSL 会打印一条警告说 hex string is too short, padding with zero bytes to length

但是,它没有提到如何(前置或附加)。

幸运的是,您可以使用 -p 查看 OpenSSL 使用的确切密钥和 IV。

显然,它在右边追加了零。

>openssl enc -aes-128-cbc -d -K 614c9b1fa9ea1b1be878929c592d -iv 0276 -nosalt -in enc -out dec -p
hex string is too short, padding with zero bytes to length
hex string is too short, padding with zero bytes to length
key=614C9B1FA9EA1B1BE878929C592D0000
iv =02760000000000000000000000000000