跳到主要内容

generate_simple_self_signed

搜索

函数 generate_simple_self_signed 

Source
pub fn generate_simple_self_signed(
    subject_alt_names: impl Into<Vec<String>>,
) -> Result<CertifiedKey<KeyPair>, Error>
展开描述

用于生成自签名证书的 KISS 函数

给定你的证书应生效的一组域名,此函数会使用合理的默认设置填充其他生成参数,并生成自签名证书及密钥对air as output.

§Example

use rcgen::{generate_simple_self_signed, CertifiedKey};
// Generate a certificate that's valid for "localhost" and "hello.world.example"
let subject_alt_names = vec!["hello.world.example".to_string(),
	"localhost".to_string()];

let CertifiedKey { cert, signing_key } = generate_simple_self_signed(subject_alt_names).unwrap();

// The certificate is now valid for localhost and the domain "hello.world.example"
println!("{}", cert.pem());
println!("{}", signing_key.serialize_pem());