openssl的使用,通过man手册查看其作用

DESCRIPTION

       OpenSSL is a cryptography toolkit implementing the Secure Sockets Layer (SSL v2/v3) and Transport Layer

     openssl是一个加密工具实现安全套接字层和安全传输层的网络协议和相关加密标准的要求

       Security (TLS v1) network protocols and related cryptography standards required by them.


       The openssl program is a command line tool for using the various cryptography functions of OpenSSL’s 

crypto library from the shell.  It can be used for


        o  Creation and management of private keys, public keys and parameters

          创建和管理私钥、公钥和参数

        o  Public key cryptographic operations

        公钥密码操作

        o  Creation of X.509 certificates, CSRs and CRLs

        创建X.509证书签名请求和证书吊销列表

        o  Calculation of Message Digests

        计算信息摘要

        o  Encryption and Decryption with Ciphers

        加密和解密运算

        o  SSL/TLS Client and Server Tests

        SSL(安全套接字层)/TLS(传输层安全)客户端和服务器测试

        o  Handling of S/MIME signed or encrypted mail

        安全的多目标邮件扩展签名或加密邮件的处理

        o  Time Stamp requests, generation and verification

        时间戳的请求、生成和验证

    openssl包含3部分:

      openssl:多用途命令行工具,各功能分别使用子命令实现,可通过openssl --help查看

          Standard commands(标准命令)

         x509证书格式、ca创建私有ca、req生成证书颁发申请、dsa使用公钥加密中的dsa算法、rsa使用公钥加密中的rsa算法、crl证书吊销列表、enc实现数据加密、passwd模拟实现password命令、speed测试某种加密算法实现的速度

        Message Digest commands(信息摘要命令)

        Ciphers commands(文件加密命令)

    libcrypto:公共加密库

    libssl: ssl协议的实现


    openssl命令工具

    查看版本号  

    [root@kvm ~]# openssl version
    OpenSSL 1.0.1e-fips 11 Feb 2013


    对称加密:

    工具:gpg,openssl enc

    算法:DES,DES3,AES,Blowfish,Twofish,RC6,idea,CAST5

    

    加密使用的命令# openssl enc -des3 -a -salt -in /path/from/somefile -out /path/to/somecipherfile

    解密使用的命令# openssl enc -d -des3 -a -salt -in /path/from/somecipherfile -out /path/to/somefile

        -a  base64 process the data. 基于base64来处理数据     

        -salt  use a salt in the key derivation routines. This is the default. 加入一些杂志,这个是默认的

       -in 指定输入文件  -out指定输出文件

     enc的使用帮助

    [root@kvm ~]# whatis enc

    enc                  (1ssl)  - symmetric cipher routines

    [root@kvm ~]# man enc 就可以查看到帮助手册了

wKiom1TKIcqS-F3NAAPehha_m3U378.jpg


    单向加密

      特性:

        one-way 单向,不可逆

        Collison-free 无冲突

      算法:

          md5:128bits

          sha1:160bits

          sha256

          sha384

          sha512

      加密工具:md5sum,sha1sum,openssl dgst,chsum

      # openssl dgst [-md5|-sha1] [-out /path/to/filename] /path/from/somefile

      使用不同的工具用相同的加密算法加密后得到的特征码是一样的

wKiom1TKJBGSWqc9AAEFTdZ5wtw405.jpg

      也可以把特征码输出到指定的文件中用-out选项即可

   

      MAC:消息摘要码,单向加密的一种延伸类的应用

        应用:用于实现在网络通信中保证所传输数据的完整性

        机制有两种:

            CBC-MAC

            HMAC:使用md5或sha1算法

      用户密码:在Centos 5上是用的是md5,Centos 6、7上使用的是sha512

        #openssl passwd -1 -salt SALT(指定salt,一般用随机数)

          -1 表示使用md5加密,是数字1  -1  Use the MD5 based BSD password algorithm 1.

wKiom1TKJv-y6bjbAAFVxkSXAy4657.jpg

        通过生成随机数做salt,不需要每次都输入salt

        # openssl rand -base64|-hex  num

        -hex   Show the output as a hex string.

wKioL1TKKZGgdBeEAAJeHwdub-0284.jpg

       


      公钥加密:

          算法:RSA,EIGamal

          工具:gpg,openssl,rsautl


     数字签名功能:

         算法:RSA,EIGamal,DSA


         DSA:Digital Signature Algorithm 数字签名算法

         DSS:Digital Signature Standard 数字签名标准


      密钥交换:IKE

        算法:公钥加密、DH Diffie-Hellman

        生成密钥:

        gendsa生成dsa密钥

        # (umask 077; openssl genrsa  -out /path/to/keyfile NUMBEROFBITS )此时是生产私钥,私钥应该是只有属主才有权限,所以生成私钥文件时指定umask为077,创建的私钥文件权限就为600了

wKiom1TKK9DDVZUqAAapS-VnVGY188.jpg

wKioL1TKLVmxI_f2AANQMJbBNwk316.jpg



      从私钥中抽取公钥

      #openssl rsa -in /path/from/private_key_file  -pubout

        -pubout
           by default a private key is output: with this option a public key will be
           output instead. This option is automatically set if the input is a public
           key.

wKioL1TKLl3hFEpPAAJW7J18QPk105.jpg

         #openssl rsa -in newkey -text -pubout

            -text
               prints out the various public or private key components in plain text in
               addition to the encoded version.
                   使用本文格式打印各公钥和私钥说明除了编码版本。

wKiom1TKLmiSBdn5AAODj5TWjg0930.jpg