Exercise 3.8 Familiarize yourself with a cryptographic software development
package for your computer. A popular open source package is OpenSSL,
though there are numerous other alternatives.
Using an existing cryptography library, decrypt the following ciphertext (in
hex)
53 9B 33 3B 39 70 6D 14 90 28 CF E1 D9 D4 A4 07
with the following 256-bit key (also in hex)
80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01
using AES.
因此我查阅了 openssl 手册页并得到了以下信息:
openssl enc -d -aes256 -K 8000000000000000000000000000000000000000000000000000000000000001 -in ciphertext.txt -out plaintext.txt -iv 0
我已将十六进制密文以二进制形式存储到文本文件密文中。我完全不知道为什么需要初始化 IV。但这给了我一个严重的解密错误。
答案1
OpenSSL 默认(大部分)使用 CBC,因此-aes256
实际上是-aes-256-cbc
,它需要 IV。-aes-256-ecb
相反,指定则不需要。(如果您尚未了解分组密码模式,请参阅https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation。)此外,这里的数据似乎没有被填充,尽管它碰巧能工作;最好指定-nopad
。有了这些,我得到了:
$ od -tx1 su1670756
0000000 53 9b 33 3b 39 70 6d 14 90 28 cf e1 d9 d4 a4 07
0000020
$ echo $K
8000000000000000000000000000000000000000000000000000000000000001
$ openssl <su1670756 enc -aes-256-ecb -d -K $K -nopad | od -tx1
0000000 80 70 60 50 40 30 20 10 08 07 06 05 04 03 02 01
0000020