使用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
阅读(9472) | 评论(0) | 转发(0) |