Openssl AES-CBC 加密命令,iv值的问题

SimonYe-记录随笔 2014-03-04 09:21:46
用Openssl来对文件进行AES-CBC方式加密的其中两个方式:一个是直接输入初始化向量,一个是不输入该向量,问题是不输入该向量的时候 Openssl是怎么处理的。。

1)openssl enc -e -aes-128-cbc -iv 0b1e1d000f0b07091d1f04071f1e0407 -k 1234567812345678 -in input.xml -out output.xml

2)openssl enc -e -aes-128-cbc -k 1234567812345678 -in input.xml -out output.xml
第二种方式的IV值是如何计算出来的
...全文
给本帖投票
15688 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
引用 3 楼 u010599631 的回复:
http://www.openssl.org/docs/apps/enc.html# 看看上面这个链接,官网上面的参数意义。 -k password the password to derive the key from. This is for compatibility with previous versions of OpenSSL. Superseded by the -pass argument. -K key the actual key to use: this must be represented as a string comprised only of hex digits. If only the key is specified, the IV must additionally specified using the -iv option. When both a key and a password are specified, the key given with the -K option will be used and the IV generated from the password will be taken. It probably does not make much sense to specify both key and password. 所以呢,小写-k并不是指定密码,而是用于生成key和iv的一串序列。 而大写-K,就是用于指定实际密码。如下面的演示图。 另外,若是指定了-K,那么一定要指定-iv,否则就要靠自动生成的,也就是-k。
你说的对的,现在我不了解的就是 用这个小写的k 是怎么自动生成 key 和 IV 值的,就是这个值的生成过程
u010599631 2014-03-12
  • 打赏
  • 举报
回复
知道这个函数是干嘛的吗?EVP_BytesToKey,给你链接看看,EVP_BytesToKey() derives a key and IV from various parameters. http://www.openssl.org/docs/crypto/EVP_BytesToKey.html 在enc中,就是用这个函数根据key生成的。 你有openssl源码?读一读就什么都知道了。 你可以根据下面这个网址,搜索openssl的任何api,都有源码可以读。至于怎么生成的,太复杂,本人没研究过,我只会简单的使用而已。 http://fossies.org/dox/openssl-1.0.1f/evp__key_8c_source.html#l00115
u010599631 2014-03-07
  • 打赏
  • 举报
回复
http://www.openssl.org/docs/apps/enc.html#
看看上面这个链接,官网上面的参数意义。
-k password
the password to derive the key from. This is for compatibility with previous versions of OpenSSL. Superseded by the -pass argument.

-K key
the actual key to use: this must be represented as a string comprised only of hex digits. If only the key is specified, the IV must additionally specified using the -iv option. When both a key and a password are specified, the key given with the -K option will be used and the IV generated from the password will be taken. It probably does not make much sense to specify both key and password.

所以呢,小写-k并不是指定密码,而是用于生成key和iv的一串序列。
而大写-K,就是用于指定实际密码。如下面的演示图。


另外,若是指定了-K,那么一定要指定-iv,否则就要靠自动生成的,也就是-k。
  • 打赏
  • 举报
回复
引用 1 楼 u010599631 的回复:
openssl加密的时候,默认iv是16个0(这个称为初始化向量),由于是分组加密,所以下一组的iv,就用前一组的加密的密文来充当,这就是cbc加密模式。 下面两个链接,第一个有分组加密的详细图解,讲述了基本原理。 第二个从openssl源码分析的角度,给出了aes加密的过程,验证了上述的图解。 http://www.cnblogs.com/adylee/archive/2007/09/14/893438.html http://yuanshuilee.blog.163.com/blog/static/217697275201311314185639/
这个我看过了,现在疑问是我在 Linux下用Openssl进行文件加密不输入IV值,用-P参数打印出来的 IV 值 和 Key 值怎么一直在变? ps:明文文件一直没有变 [root@WilliamFedora test]# openssl enc -e -aes-128-cbc -k 1234567812345678 -p -in inputor.xml -out input.xml salt=5C54561974AE7FF8 key=7C3AF6DF038CE6AAC6D6D590220F3C62 iv =C7272358A3FB70E207CDB0F616CA8685 [root@WilliamFedora test]# openssl enc -e -aes-128-cbc -k 1234567812345678 -p -in inputor.xml -out input.xml salt=7FD429763E2F9805 key=ECCE7BE04C7EBB323D233288F8AAF7E9 iv =2DBB7B463B607B66087EB4D96B2DCF0B [root@WilliamFedora test]# openssl enc -e -aes-128-cbc -k 1234567812345678 -p -in inputor.xml -out input.xml salt=6B60159F37052670 key=445D7BAC30C2ECE7B7C4420013327863 iv =68B74B71CE1F96190D03BBEB01F01DE3
u010599631 2014-03-04
  • 打赏
  • 举报
回复
openssl加密的时候,默认iv是16个0(这个称为初始化向量),由于是分组加密,所以下一组的iv,就用前一组的加密的密文来充当,这就是cbc加密模式。 下面两个链接,第一个有分组加密的详细图解,讲述了基本原理。 第二个从openssl源码分析的角度,给出了aes加密的过程,验证了上述的图解。 http://www.cnblogs.com/adylee/archive/2007/09/14/893438.html http://yuanshuilee.blog.163.com/blog/static/217697275201311314185639/

18,829

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 专题技术讨论区
社区管理员
  • 专题技术讨论区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧

手机看
关注公众号

关注公众号

客服 返回
顶部