1. rcgen 包介绍
Rust X.509 certificate generator
2.包应用案例
3. 生成自签名证书
3.1 证书生成
主要设置以下字段
Issuer
: “rcgen self signed cert”
Subject
: “rcgen self signed cert”
Subject Alternative Name
可设置 DNS
或 IPAddress
Cargo.toml
配置添加以下相关的包
[ dependencies]
rcgen = "0.10.0"
rsa = "0.9.2"
rand = "0.8.5"
ring = "0.16.20"
pem = {
version = "2.0.1" }
time = {
version = "0.3" , features = [ "macros" , "local-offset" ] }
代码部分
mod x509m {
use rand:: rngs:: OsRng ;
use rcgen:: {
BasicConstraints , CertificateParams , DistinguishedName , DnType , IsCa , SanType } ;
use rcgen:: {
Certificate , KeyUsagePurpose } ;
use rsa:: {
pkcs8:: EncodePrivateKey , RsaPrivateKey } ;
use std:: net:: {
IpAddr , Ipv4Addr } ;
use time:: ext:: NumericalDuration ;
use