SigningKey cannot be serialized to a pem format
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
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.
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?
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.
ed25519-dalek has moved to: https://github.com/dalek-cryptography/curve25519-dalek/tree/main/ed25519-dalek
If you feel this issue has not yet been addressed, please request this issue be moved to that repo by leaving a comment, or open a new issue on that repo.