Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15369712
  • 博文数量: 2005
  • 博客积分: 11986
  • 博客等级: 上将
  • 技术积分: 22535
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-17 13:56
文章分类

全部博文(2005)

文章存档

2014年(2)

2013年(2)

2012年(16)

2011年(66)

2010年(368)

2009年(743)

2008年(491)

2007年(317)

分类:

2010-02-06 16:51:14

使用mcrypt工具进行aes-cbc-128加解密实例
hex2bin工具源码
对于加密,如果没有使用-S指定hsalt,那么openssl会
调用RAND_pseudo_bytes(salt, sizeof salt)随机产生一个salt值,
当然salt和magic是用来综合产生key和iv的,如果使用-K和-iv强行指定了key和iv的话,
那么-S就没有任何意义了,因为虽然-S也执行,但是函数根据salt产生的key和iv
EVP_BytesToKey(cipher,dgst,sptr, (unsigned char *)str, strlen(str),1,key,iv);
将在下面
if ((hiv != NULL) && !set_hex(hiv,iv,sizeof iv))
if ((hkey != NULL) && !set_hex(hkey,key,sizeof key))
直接覆盖,所以最终会使用用户自定义的十六进制格式key和iv来加密数据,因为没有定义password,所以也就不会生成magic和salt这16个字节数据域到out输出文件中.

luther@gliethttp:~$ openssl aes-128-cbc -v -p -iv 00000000000000000000000000000000 -K 00000000000000000000000000000000 -in zeror -out zeror.cbc
salt=84A82400DC3E0B08
key=00000000000000000000000000000000
iv =00000000000000000000000000000000
bytes read   :      16
bytes written:      32

luther@gliethttp:~$ openssl aes-128-cbc -v -p -iv 00000000000000000000000000000000 -K 00000000000000000000000000000000 -d -in  zeror.cbc -out 333
salt=84581B00DC3E0B08
key=00000000000000000000000000000000
iv =00000000000000000000000000000000
bytes read   :      32
bytes written:      16


luther@gliethttp:~$ openssl aes-128-cbc -v -p -iv 00000000000000000000000000000000 -K 00000000000000000000000000000000 -in cip -out cip.cbc
salt=84685C00DC3E0B08
key=00000000000000000000000000000000
iv =00000000000000000000000000000000
bytes read   :      16
bytes written:      32


luther@gliethttp:~$ openssl aes-128-cbc -v -p -d -pass pass:123 < ciper.bin
salt=7437F0D0E86287C3
key=FEB051184865FD8800E06B40775B2184
iv =3B3F1B9E39C577169237C56F2B630BA2
123
bytes read   :      32
bytes written:       4

luther@gliethttp:~$ openssl aes-128-cbc -v -p -iv 3B3F1B9E39C577169237C56F2B630BA2 -d -pass pass:123 < ciper.bin
salt=7437F0D0E86287C3
key=FEB051184865FD8800E06B40775B2184
iv =3B3F1B9E39C577169237C56F2B630BA2
123
bytes read   :      32
bytes written:       4

luther@gliethttp:~$ openssl aes-128-cbc -v -p -K FEB051184865FD8800E06B40775B2184 -iv 3B3F1B9E39C577169237C56F2B630BA2 -d -pass pass:123 < ciper.bin
salt=7437F0D0E86287C3
key=FEB051184865FD8800E06B40775B2184
iv =3B3F1B9E39C577169237C56F2B630BA2
123
bytes read   :      32
bytes written:       4
阅读(9344) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~