openssl enc 加密/解密文件

OpenSSL 可用密码或者秘钥方式进行加密,近期用到用密码进行加密解密,故记录之。

AES256 是对称加密的一种,可参考相关博客
在这里插入图片描述

加密(openssl enc -e):
openssl enc -e -aes256 -pbkdf2 -iter INT_NUM -k YOUR_PASSWORD -in /YOUR_PATH/FILE -out /YOUR_PATH/ENCRYPTED_FILE

解密(openssl enc -d):
openssl enc -d -aes256 -pbkdf2 -iter INT_NUM -k YOUR_PASSWORD -in /YOUR_PATH/ENCRYPTED_FILE -out /YOUR_PATH/FILE

如果不加 -pbkdf2 -iter INT_NUM,会报warning(官方建议加上 -pbkdf2

实例:
加密:openssl enc -e -aes256 -pbkdf2 -iter 100 -k 123456 -in ./aaa.txt -out ./dist/aaa.encrypted
解密:openssl enc -d -aes256 -pbkdf2 -iter 100 -k 123456 -in ./dist/aaa.encrypted -out ./aaa.txt

参数解释:
在这里插入图片描述

参考资料:
【openssl官网】https://wiki.openssl.org/index.php/Enc
【密码/秘钥加密】https://my.oschina.net/u/728245/blog/789761
【关于warning的避免】https://stackoverflow.com/questions/16056135/how-to-use-openssl-to-encrypt-decrypt-files

猜你喜欢

转载自blog.csdn.net/muyao987/article/details/126732573