[root@aa ~]# openssl version
OpenSSL 1.0.1e-fips 11 Feb 2013
[root@aa ~]#
[root@aa ~]# whatis enc
enc (1ssl) - symmetric cipher routines
[root@aa tmp]# openssl enc -e -des3 -a -salt -in fstab -out fstab.ciphertext -e:加密格式;-a:基于文本编码;-salt:自动加入杂志;-in:加密哪个文件;-out:输出到哪个路径
enter des-ede3-cbc encryption password:
Verifying - enter des-ede3-cbc encryption password:
[root@aa tmp]# rm fstab
rm: remove regular file ‘fstab’? y
[root@aa tmp]# cat fstab.ciphertext
U2FsdGVkX19TOyfPaUaIYrL3f6FYQiOtsVxUOZBUsAbz+9uYXkjM4Wd9xvbz4Fpu
YwRWE8XyiQOnofveK3EoNOuma628gxfyQwQUNYm2j+Jo2OY7eMsdZ8Tqq6bY22pb
n3CRCurVKR/uZ6sNe8GxkPo4NeEyPB9qdpgpV9xo52zY4HUxqkeiJ98XizNe1Yqn
IoKqWxM24dG6O6nBnZL77qPVXfvNLmvjSXBloMXv3ZqWwO1KND/z2UCCeKnEn4Qv
9a3XLybBcTvi2oMMFOd/ouptPMsDdJgpF2dM/P5SXihVH5cbqDoVIxdxd2s98Nl6
h0E1zXzRumph12Ko3KgEd/GU/sq9rTKyB9OiSsQgh1+SaeatDrbJwZTNuTz9vztS
J3UnPzOgl0GIVSx1UDdb6lbfBhR/36YtRZHEqtCS6TjQKizJKSy/7jzqHFjMmxcJ
XlHyun4bgR4dMZ+TMqjoDgu9qGgw4yGeRgMR+fKUGiXZPbWdFD12DwESqL1NfQ5f
wQpqr/YEMtEgeXHPL4fHps1rgYFRXlvFcR+hiO2wPwTxrllY0psaM2cifC0F0vH3
[root@aa tmp]#
[root@aa tmp]# openssl enc -d -des3 -a -salt -in fstab.ciphertext -out fstab
enter des-ede3-cbc decryption password:
[root@aa tmp]# ls
fstab fstab.ciphertext
[root@aa tmp]# cat fstab
#
# /etc/fstab
# Created by anaconda on Thu Jun 16 09:45:02 2016
#
# Accessible filesystems, by reference, are maintained under ‘/dev/disk‘
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=61a8ab18-e2f0-4857-bf8e-a8e534b08c9c / xfs defaults 0 0
UUID=4c401c24-2f32-49af-96e5-bc2ea947387a /boot xfs defaults 0 0
[root@aa tmp]# whatis dgst
dgst (1ssl) - message digests
[root@aa tmp]# md5sum fstab
c68a89b85a3b2177fee40201320acd35 fstab
[root@aa tmp]# openssl dgst -md5 fstab
MD5(fstab)= c68a89b85a3b2177fee40201320acd35
[root@aa tmp]#
[root@aa tmp]# openssl dgst -md5 -hex fstab #默认十六进制编码
MD5(fstab)= c68a89b85a3b2177fee40201320acd35
[root@aa tmp]# whatis passwd
passwd (1) - update user‘s authentication tokens
sslpasswd (1ssl) - compute password hashes ***
passwd (5) - password file
-1:MD5;-salt 123:加入杂质;
[root@aa tmp]# openssl passwd -1 -salt 123
Password:
$1$123$nE5gIYTYiF1PIXVOFjQaW/
[root@aa tmp]#
[root@aa tmp]# openssl rand -base64 4
rLMepA==
[root@aa tmp]# openssl rand -hex 4
3d386d6e #4个字节,8位16进制
[root@aa tmp]# whatis rsautl
rsautl (1ssl) - RSA utility
[root@aa tmp]# whatis genrsa
genrsa (1ssl) - generate an RSA private key
[root@aa tmp]# ls /dev | egrep "random|uinput"
random
uinput
[root@aa tmp]# whatis random
random (3) - random number generator
[root@aa tmp]# whatis urandom
urandom (4) - kernel random number source devices
[root@aa tmp]#
[root@aa tmp]# openssl genrsa -out rsakey.private 2048
Generating RSA private key, 2048 bit long modulus
......+++
............+++
e is 65537 (0x10001)
[root@aa tmp]# cat rsakey.private
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEA6vl3ePFVYl3DirG1dqgb/PRmjrAuSwmGp/9MligRjDA1Uo7y
dkDHEmiAGb6Ubt5w4T5B525bQMqD0TsG1lRwH6Gc9awd5ct1tR29m+lSobFqFvrJ
W558k25G3C7OEXie1+vc8AiA2cKiLgE9MckPWiBARK9C0UqUUiHOd6Z6kjDflr0p
uS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0yV+gmnJMhCJ58ZyVaJxVuRhs3HWnep
AcHGAc2/l1+Zw2WFd85Ohl8FQMbvPVHH7gUf+7yF+FRi7l9gyIuMABGKvgfbXiKz
4H5Doq+7qXmToa0m/tHAf2MN/vOsj7MbSw/AgIhrCJhiwAWXK+2XlzuAIm7d4l2I
cAGS8sECgYEAuqa7Yv+WbeovFutgnExdmvvO0Z0oHb1tkwUI+RG/uwJOQdzpMsNE
Osk1HWfao3nu7P+4v5WFFDbqA0kyCO0mTIT/gBy8je+d4iWfdsl1HtINim6lp6cL
560wSJSWgiJXo0fX5YlLvW9DS7ZIhTOkip32bGcpyyBSGO/6Kqt85CA=
-----END RSA PRIVATE KEY-----
[root@aa tmp]# openssl rsa -in rsakey.private -pubout
writing RSA key
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6vl3ePFVYl3DirG1dqgb
/PRmjrAuSwmGp/9MligRjDA1Uo7ydkDHEmiAGb6Ubt5w4T5B525bQMqD0TsG1lRw
H6Gc9awd5ct1tR29m+lSobFqFvrJW558k25G3C7OEXie1+vc8AiA2cKiLgE9MckP
WiBARK9C0UqUUiHOd6Z6kjDflr0puSuKuvnoOUWyLe3WVj5vpA4jYxyFGiqW8E3C
rh8aVExnsH8rdE3V4EuWASzGOmGGXjN+F7Hm6hKgOFBazN5o2RAQ3/PknduQrSBY
vkOQKHoaDpi+hFWSu7V6PCZd9nl7uKt5D3i4W+4IrrTuiWN+/3pLJhzijB3sT2pZ
IQIDAQAB
-----END PUBLIC KEY-----
[root@aa tmp]# chmod og= rsakey.private
[root@aa tmp]# ll rsakey.private
-rw-------. 1 root root 1679 Aug 5 20:59 rsakey.private
[root@aa tmp]#
[root@aa tmp]# (umask 077; openssl genrsa -out key.pri 2048)
Generating RSA private key, 2048 bit long modulus
...+++
..............+++
e is 65537 (0x10001)
[root@aa tmp]# ll key.pri
-rw-------. 1 root root 1679 Aug 5 21:06 key.pri
原文地址:http://blog.51cto.com/zhongle21/2091435