在Linux下使用OpenSSL命令行时,有一些技巧可以帮助你更高效地完成任务。以下是一些常用的技巧:
openssl rand
命令生成随机数,可以指定输出格式(如base64或hex)和长度。openssl rand -base64 30 # 生成30字节的base64编码随机数
openssl rand -hex 30 # 生成30字节的hex编码随机数
openssl passwd
命令对密码进行哈希处理,支持多种加密算法(如-crypt、-1、-apr1),并可以添加盐值以增加安全性。openssl passwd -crypt 123456 # 使用默认的-crypt算法加密密码
openssl passwd -salt 'salt' 123456 # 使用指定的盐值加密密码
openssl enc -aes-256-cbc -salt -in inputfile -out encryptedfile -k mypassword
openssl enc -aes-256-cbc -d -in encryptedfile -out decryptedfile -k mypassword
openssl dgst -sha256 -sign privatekey.pem inputfile > signature
openssl dgst -sha256 -verify publickey.pem -signature signature inputfile
/etc/bash.bashrc
或/etc/profile.d/bash_completion.sh
文件来启用。string="username:homedir:shell"
echo "${string##*:}" # 直接使用变量扩展获取第三列,比使用cut更快
wget https://www.openssl.org/source/openssl-1.0.2n.tar.gz
tar -zxvf openssl-1.0.2n.tar.gz
cd openssl-1.0.2n
./config --prefix=/usr/local/ssl shared
make install
通过这些技巧,你可以更高效地在Linux环境下使用OpenSSL命令行工具,提升工作效率和安全性。