第6周作业

本文详细介绍了如何在CentOS7上使用gpg创建RSA密钥对,并将公钥导入CentOS8进行加密解密操作。此外,还展示了如何在CentOS7中创建和管理CA,签发证书,以及撤销证书的过程。

时间:8.31 - 9.5

  1. 在 CentOS7 中使用 gpg 创建 RSA 非对称密钥对

    [Centos7root@Sat Sep 05 tmp]# cat /etc/redhat-release 
    CentOS Linux release 7.7.1908 (Core)
    [Centos7root@Sat Sep 05 tmp]# gpg --list-keys
    [Centos7root@Sat Sep 05 tmp]# gpg --gen-key
    [Centos7root@Sat Sep 05 tmp]# gpg --list-keys
    /root/.gnupg/pubring.gpg
    ------------------------
    pub   2048R/94C7C969 2020-09-05
    uid                  TreeZeng
    sub   2048R/D37B59A6 2020-09-05
    [Centos7root@Sat Sep 05 tmp]# gpg -a --export -o TreeZeng.pubkey   # gpg生成私钥时不会自动生成公钥,需要手动导出公钥(公钥是可以通过私钥计算出来的)
    [Centos7root@Sat Sep 05 tmp]# ls
    TreeZeng.pubkey
    
  2. 将 CentOS7 导出的公钥,拷贝到 CentOS8 中,在 CentOS8 中使用 CentOS7 的公钥加密一个文件

    [Centos7root@Sat Sep 05 tmp]# scp TreeZeng.pubkey 172.16.135.202:/tmp
    [root@CentOS8 tmp]# cat /etc/redhat-release 
    CentOS Linux release 8.2.2004 (Core) 
    [root@CentOS8 tmp]# gpg --list-keys 
    [root@CentOS8 tmp]# gpg --import TreeZeng.pubkey 
    gpg: key FA968E6B94C7C969: public key "TreeZeng" imported
    gpg: Total number processed: 1
    gpg:               imported: 1
    [root@CentOS8 tmp]# gpg --list-keys
    /root/.gnupg/pubring.kbx
    ------------------------
    pub   rsa2048 2020-09-05 [SC]
          A2790C03236DC8ED2EAB833BFA968E6B94C7C969
    uid           [ unknown] TreeZeng
    sub   rsa2048 2020-09-05 [E]
    [root@CentOS8 tmp]# echo "data from CentOS8" > content.txt 
    [root@CentOS8 tmp]# gpg -e -r TreeZeng content.txt 
    ...
    Use this key anyway? (y/N) y
    [root@CentOS8 tmp]# ls
    content.txt  content.txt.gpg  TreeZeng.pubkey
    
  3. 回到 CentOS7 服务器,远程拷贝 file.txt.gpg 文件到本地,使用 CentOS7的私钥解密文件

    [Centos7root@Sat Sep 05 tmp]# scp 172.16.135.202:/tmp/content.txt.gpg .
    root@172.16.135.202's password: 
    content.txt.gpg
    [Centos7root@Sat Sep 05 tmp]# gpg -o content.txt -d content.txt.gpg 
    gpg: encrypted with 2048-bit RSA key, ID D37B59A6, created 2020-09-05
          "TreeZeng"
    [Centos7root@Sat Sep 05 tmp]# cat content.txt
    data from CentOS8
    
  4. 在 CentOS7 中使用 openssl 软件创建 CA

    [Centos7root@Sat Sep 05 CA]# (umask 077; openssl genrsa -out private/cakey.pem 4096)
    Generating RSA private key, 4096 bit long modulus
    ................................................................++
    ....................................++
    e is 65537 (0x10001)
    [Centos7root@Sat Sep 05 CA]# pwd
    /etc/pki/CA
    [Centos7root@Sat Sep 05 CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 365
    ...
    [Centos7root@Sat Sep 05 CA]# ls
    cacert.pem  index.txt  newcerts  private  serial
    
  5. 在 CentOS7 中使用 openssl 软件创建一个证书申请请求文件,并使用上面的跟证书对其进行签署

    [Centos7root@Sat Sep 05 tmp]# pwd
    /tmp
    (umask 066; openssl genrsa -out test.key 2048)
    [Centos7root@Sat Sep 05 tmp]# openssl req -new -key test.key -out test.crt
    ...
    [Centos7root@Sat Sep 05 tmp]# ls
    test.csr  test.key
    [Centos7root@Sat Sep 05 tmp]# openssl ca -in test.csr -out test.crt -days 100
    
  6. 吊销已经签署成功的证书

    [Centos7root@Sat Sep 05 tmp]# openssl x509 -in test.crt -noout -serial -subject
    serial=01
    subject= /C=CN/ST=HeNan/O=T/OU=R/CN=treezeng.cn
    [Centos7root@Sat Sep 05 tmp]# openssl ca -revoke test.crt
    Using configuration from /etc/pki/tls/openssl.cnf
    Revoking Certificate 01.
    [Centos7root@Sat Sep 05echo 01 > /etc/pki/CA/crlnumber
    [Centos7root@Sat Sep 05openssl ca -gencrl -out /etc/pki/CA/crl.pem
    Using configuration from /etc/pki/tls/openssl.cnf
    
基于粒子群优化算法的p-Hub选址优化(Matlab代码实现)内容概要:本文介绍了基于粒子群优化算法(PSO)的p-Hub选址优化问题的研究与实现,重点利用Matlab进行算法编程和仿真。p-Hub选址是物流与交通网络中的关键问题,旨在通过确定最优的枢纽节点位置和非枢纽节点的分配方式,最小化网络总成本。文章详细阐述了粒子群算法的基本原理及其在解决组合优化问题中的适应性改进,结合p-Hub中转网络的特点构建数学模型,并通过Matlab代码实现算法流程,包括初始化、适应度计算、粒子更新与收敛判断等环节。同时可能涉及对算法参数设置、收敛性能及不同规模案例的仿真结果分析,以验证方法的有效性和鲁棒性。; 适合人群:具备一定Matlab编程基础和优化算法理论知识的高校研究生、科研人员及从事物流网络规划、交通系统设计等相关领域的工程技术人员。; 使用场景及目标:①解决物流、航、通信等网络中的枢纽选址与路径优化问题;②学习并掌握粒子群算法在复杂组合优化问题中的建模与实现方法;③为相关科研项目或实际工程应用提供算法支持与代码参考。; 阅读建议:建议读者结合Matlab代码逐段理解算法实现逻辑,重点关注目标函数建模、粒子编码方式及约束处理策略,并尝试调整参数或拓展模型以加深对算法性能的理解。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值