Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add private key export to PKCS#8 in DER format #1374

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

lydiabritt1987
Copy link

I need to export private keys in PKCS#8 DER format, currently the bindings only support exporting DER as a raw RSA key, or PEM in PKCS#8. At present I'm working around this by chopping off the header and trailer, then parsing the base64 back into DER, which feels a bit silly.

This pull request isn't finished; it has a memory leak still, which I'm not sure how to fix. Anyone able to help?


pub fn private_key_to_der_pkcs8(&self) -> Result<Vec<u8>, ::error::ErrorStack> {
unsafe {
let p8inf = cvt_p(ffi::EVP_PKEY2PKCS8(self.as_ptr()))?;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This library typically tries to map individual OpenSSL functions to individual Rust methods, so this would be split into a method that returns a Pkcs8PrivKeyInfo, and a method on that to turn that into DER.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants