1 use openssl::{pkey::PKey, rsa::Rsa};
2 use std::io::{Error, ErrorKind};
5 pub private_key: String,
6 pub public_key: String,
9 /// Generate the asymmetric keypair for ActivityPub HTTP signatures.
10 pub fn generate_actor_keypair() -> Result<Keypair, Error> {
11 let rsa = Rsa::generate(2048)?;
12 let pkey = PKey::from_rsa(rsa)?;
13 let public_key = pkey.public_key_to_pem()?;
14 let private_key = pkey.private_key_to_pem_pkcs8()?;
15 let key_to_string = |key| match String::from_utf8(key) {
17 Err(e) => Err(Error::new(
19 format!("Failed converting key to string: {e}"),
23 private_key: key_to_string(private_key)?,
24 public_key: key_to_string(public_key)?,