Open nicklan opened 3 years ago
Ahh, the key_der
arg has to be pkcs8 encoded (might be nice to specify that in the docs). for anyone looking to do something like this in the future, you can convert pkcs1 der bytes to pkcs8 like so:
// convert a pkcs1 der to pkcs8 format
fn pkcs1to8(pkcs1: &[u8]) -> Vec<u8> {
let oid = ObjectIdentifier::from_slice(&[1, 2, 840, 113_549, 1, 1, 1]);
yasna::construct_der(|writer| {
writer.write_sequence(|writer| {
writer.next().write_u32(0);
writer.next().write_sequence(|writer| {
writer.next().write_oid(&oid);
writer.next().write_null();
});
writer.next().write_bytes(pkcs1);
})
})
}
I'm trying to convert a pem key/cert into a pkcs12 (so the equivalent of
openssl pkcs12 -export -out client.pfx -inkey client_key.pem -in client_crt.pem
).I'm using the pem crate to get the der encoded data.
Here's the code I'm using to convert:
Trying to do
openssl pkcs12 -info -in output.pfx
on the created file gives:Any help would be much appreciated :)