书接上回。在《LDAP 密码加密方式初探》一文中,使用 OpenSSL 命令 AES 算法加密解密时,都用到了 Key 和 IV 参数,那么这两个参数是如何生成的呢?
仍然以 AES-256-CBC 开始探索。先准备好生成 Key 和 IV 的 passphrase:
$ echo -n “drjom(&)(&)MOJRD” > passphrase
上述回文形式的 passphrase 来自一个神秘的组织:)
将此 passphrase 传入 openssl 命令生成对应的 Key 和 IV:
$ openssl enc -aes-256-cbc -kfile passphrase -md md5 -P -salt
salt=51D9C4B24C759179
key=BBF4EA0E7A0EBD7C60CCE2024E218A53BBB69CCA65B4D0B705E37080676E5F5D
iv =8E5EC1AC2191167DF9B753BA93A1E7B8
其中的 salt 是随机生成的,因此每次执行的结果并不相同。而 Key 和 IV 的生成方法参考 SuperUser 的一个回答补充及验证如下(注意 md5sum 输出的结果与上述 openssl 命令的输出结果比较):
$ perl -e ‘print pack “H“, “51D9C4B24C759179″‘ > salt
$ cat passphrase salt > hash1_128.tmp
$ md5sum hash1_128.tmp
bbf4ea0e7a0ebd7c60cce2024e218a53 hash1_128.tmp
$ perl -e ‘print pack “H“, “bbf4e