我读到AES 128 CTR 模式应该适用于 16 字节(128 位)的块,如 CBC 模式。
实际上,如果我尝试使用 openssl 对 18 字节纯文本进行编码:
max@jarvis:~$ printf 0123456789abcdefgh | openssl enc -e -nopad -nosalt -aes-128-cbc -K 00000000000000000000000000000000 -iv 00000000000000000000000000000000 | hd
bad decrypt
140670739715200:error:0607F08A:digital envelope routines:EVP_EncryptFinal_ex:data not multiple of block length:../crypto/evp/evp_enc.c:425:
00000000 14 f5 fe 74 69 66 f2 92 65 1c 22 88 bb ff 46 09 |...tif..e."...F.|
00000010
max@jarvis:~$ printf 0123456789abcdefgh | openssl enc -e -nosalt -aes-128-cbc -K 00000000000000000000000000000000 -iv 00000000000000000000000000000000 | hd
00000000 14 f5 fe 74 69 66 f2 92 65 1c 22 88 bb ff 46 09 |...tif..e."...F.|
00000010 c2 ae b2 99 18 cd 6e ee 55 92 77 d9 e8 f3 1f bf |......n.U.w.....|
00000020
密文是 16 或 32 字节,取决于-nopad
参数的存在。
但如果我尝试点击率:
max@jarvis:~$ printf 0123456789abcdefgh | openssl enc -e -nopad -nosalt -aes-128-ctr -K 00000000000000000000000000000000 -iv 00000000000000000000000000000000 | hd
00000000 56 d8 79 e7 db bf 1a 0c b0 75 9b 3b a9 50 4e 48 |V.y......u.;.PNH|
00000010 3f 8a |?.|
00000012
max@jarvis:~$ printf 0123456789abcdefgh | openssl enc -e -nosalt -aes-128-ctr -K 00000000000000000000000000000000 -iv 00000000000000000000000000000000 | hd
00000000 56 d8 79 e7 db bf 1a 0c b0 75 9b 3b a9 50 4e 48 |V.y......u.;.PNH|
00000010 3f 8a |?.|
00000012
在每种情况下,密文都是 18 个字节,就像明文一样。
我不知道为什么