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

SigningKey cannot be serialized to a pem format #323

Open
lebe-dev opened this issue Nov 21, 2024 · 3 comments
Open

SigningKey cannot be serialized to a pem format #323

lebe-dev opened this issue Nov 21, 2024 · 3 comments

Comments

@lebe-dev
Copy link

Hi.

SigningKey cannot be serialized to a pem format:

use ed25519_dalek::SigningKey;
use rand::rngs::OsRng;
...

let mut csprng = OsRng;
let signing_key: SigningKey = SigningKey::generate(&mut csprng);

match signing_key.to_pkcs1_pem(rsa::pkcs1::LineEnding::LF) {
    Ok(_) => {}
    Err(e) => {
        error!("{}", e)
    }
}

Cargo.toml:

ed25519-dalek = { version = "2.1.1", features = [
    "digest",
    "pem",
    "pkcs8",
    "signature",
    "serde",
    "rand_core",
] }

Error:

unknown/unsupported algorithm OID: 1.2.840.113549.1.1.1
@tarcieri
Copy link
Contributor

PKCS#1 is a format for RSA keys, not Ed25519 keys.

You want PKCS#8. See: https://docs.rs/ed25519-dalek/2.1.1/ed25519_dalek/#pkcs8-key-encoding

The fact you can call this at all is something of a quirk of the pkcs1 crate's API which should probably be fixed.

@lebe-dev
Copy link
Author

lebe-dev commented Nov 22, 2024

Thanks, but i don't get how to use it for SigningKey. I couldn't find implementation for ed25519_dalek::pkcs8::EncodePrivateKey and how to use it in SigningKey context.

Could you provide a small example?

@tarcieri
Copy link
Contributor

tarcieri commented Dec 2, 2024

The trait impl is here: https://docs.rs/ed25519-dalek/latest/ed25519_dalek/struct.SigningKey.html#impl-EncodePrivateKey-for-SigningKey

We should add an example to the documentation.

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

No branches or pull requests

2 participants